Pular para o conteúdo

Usando o FORMAT [RESOLVIDO]

Responder tópico
  • Denunciar
  • Indicar

1. Usando o FORMAT [RESOLVIDO]

Enviado em 03/08/2015 - 15:19h

Olá pessoal!Estou fazendo o seguite programa:

program foo
implicit none
character(len=1024) :: filename
integer:: X,Y
X=5
Y=2
write (filename, 10) "hello", 10
10 FORMAT(AX,IY)
print *, trim(filename)
end program
Mas quando executo parece:

10 FORMAT(A'X',I'int(Y)')
1
Error: Nonnegative width required in format string at (1)
teste.f90:7.23:

write (filename, 10) "hello", 10
1
Error: FORMAT label 10 at (1) not defined
Só que quero poder declarar os tamanhos das string e inteiros antes do FORMAT igual ao programa!
Alguém pode me ajudar nisso? Se sim, ficarei muito agradecido!

Responder tópico

2. Re: Usando o FORMAT [RESOLVIDO]

Melhor resposta

Enviado em 04/08/2015 - 00:23h

Eu tenho exemplo de dois códigos em Fortran com máscara de formatação, mas mais adequados a Fortran 95.
Seu código pode ser modificado para semelhante?

* http://www.vivaolinux.com.br/script/Crivo-de-Eratostenes-Simples-em-Fortran-95/
* http://www.vivaolinux.com.br/script/Funcao-Fatorial-Recursiva-em-Fortran-95/

Tente modificar o modo de formatação.

--
http://s.glbimg.com/po/tt/f/original/2011/10/20/a97264_w8.jpg

Encryption works. Properly implemented strong crypto systems are one of the few things that you can rely on. Unfortunately, endpoint security is so terrifically weak that NSA can frequently find ways around it. — Edward Snowden

3. Re: Usando o FORMAT [RESOLVIDO]

Enviado em 05/08/2015 - 11:26h

listeiro_037 escreveu:

Eu tenho exemplo de dois códigos em Fortran com máscara de formatação, mas mais adequados a Fortran 95.
Seu código pode ser modificado para semelhante?

* http://www.vivaolinux.com.br/script/Crivo-de-Eratostenes-Simples-em-Fortran-95/
* http://www.vivaolinux.com.br/script/Funcao-Fatorial-Recursiva-em-Fortran-95/

Tente modificar o modo de formatação.

--
http://s.glbimg.com/po/tt/f/original/2011/10/20/a97264_w8.jpg

Encryption works. Properly implemented strong crypto systems are one of the few things that you can rely on. Unfortunately, endpoint security is so terrifically weak that NSA can frequently find ways around it. — Edward Snowden
Consegui adaptar fazendo:

program foo
implicit none
character(len=1024) :: filename
integer::Y, X
character*8:: F1
character*20:: str
Y=5
X=2
F1='(A'//trim(str(Y))//',I'//trim(str(X)) //')'
write (filename, F1) "hello", 10
print *, trim(filename)
end program

character(len=20) function str(k)
! "Convert an integer to string."
integer, intent(in) :: k
write (str, *) k
str = adjustl(str)
end function str
Nome: Francisco Iago Lira Passos
Curso: Bacharelado em Física

Responder tópico

Responder tópico

Entre na sua conta para responder.

Fazer login para responder