forums.silverfrost.com
Welcome to the Silverfrost forums

Author Message
Anonymous
Guest

Posted: Thu Oct 21, 2004 2:31 pm    Post subject: Write format

Hello,

I have an array with n² values (n=1,3,5,7). I would like to display it with n lines of n elements (I want to see a matrix in my console window).
At school, I have learnt the syntax :
 Code: WRITE (*,'(I3)')
, with n an integer defined in the programm and put into hooks to specify to the compiler that it's an integer already defined.
How can I do with FTN 95 ?

That's my code :

 Code: PROGRAM carre_magique IMPLICIT NONE INTEGER :: n,p,i,j INTEGER :: error,somme INTEGER,ALLOCATABLE :: grand_carre(:, INTEGER,ALLOCATABLE :: c_haut(:,,c_bas(:,,c_droite(:,,c_gauche(:,,petit_carre(:, !entete WRITE (*,*) "Construction d'un carre magique de taille impaire n=2p+1" WRITE (*,"(A,\$)") "Valeur de p (00) .AND. (p<5)) EXIT WRITE (*,*) "Attention : 0 carre magique final petit_carre = petit_carre + c_haut + c_bas + c_gauche + c_droite !affichage du resultat WRITE (*,*) WRITE (*,'(A,I2,A)') "Voici un carre magique d'ordre ",n," :" WRITE (*,*) WRITE (*,'(I3)') petit_carre !affichage de la constante prevue pour ce carre WRITE (*,*) WRITE (*,'(A,I4,A)') "Verification : la constante vaut",n*(n*n+1)/2 WRITE (*,*) !sommes de controle : lignes, colonnes, diagonales WRITE (*,*) "Les lignes ont pour somme :" DO i=1,n somme = 0 DO j=1,n somme = somme + petit_carre(i,j) ENDDO WRITE (*,'(I4,\$)') somme ENDDO WRITE (*,*) WRITE (*,*) "Les colonnes ont pour somme :" DO i=1,n somme = 0 DO j=1,n somme = somme + petit_carre(j,i) ENDDO WRITE (*,'(I4,\$)') somme ENDDO WRITE (*,*) WRITE (*,*) "Les diagonales ont pour somme :" somme = 0 DO i=1,n somme = somme + petit_carre(i,i) ENDDO WRITE (*,'(I4,\$)') somme somme = 0 DO i=1,n somme = somme + petit_carre(n+1-i,i) ENDDO WRITE (*,'(I4)') somme !liberation de la memoire DEALLOCATE(grand_carre,petit_carre,c_haut,c_bas,c_gauche,c_droite) !pause finale de la console WRITE(*,*) WRITE(*,*) "Appuyez sur " READ (*,*) END PROGRAM

TL
Martin

Joined: 09 Sep 2004
Posts: 43

 Posted: Tue Oct 26, 2004 7:35 am    Post subject: Write format You can construct a format string at runtime using internal file I/O. Here is an example: program run_time_format character*100 my_format integer n n = 2 write (my_format, "(A,I0,A)") "(", n, "I3)" write (*, my_format) 43, 6 end
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First
 All times are GMT + 1 Hour Page 1 of 1