Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
2326 connectés 

  FORUM HardWare.fr
  Programmation
  Divers

  Programmation avec Fortran ?

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Programmation avec Fortran ?

n°2169872
Jill_the_R​eturn
Posté le 04-01-2013 à 15:08:25  profilanswer
 

Bonjour  
En cours j'utilise le logiciel Fortran (logiciel de programmation)  
 
Je dois créer un programme capable de lire un forman .dat  
Mais je n'arrive pas à écrire mon program, je sais qu'il faut utiliser la fonction  
open = ( unit = ..., file = "nom".dat ..)  
 
J'ai besoin d'aide svp   :)  
 
Voici l'énoncé de mon devoir  
 
A file homework_6.dat contains book records: Name (up to 25 characters), publish year (4 digit integer), price (6 digit real), ISBN (13 digit integer). Write a program to read the file (homework_6.dat) and print out (on screen or into another file) the details in the following format:
 
                                        Publish    
          Name                        Year        ($)          ISBN
       -------------------------      ----      ------      -------------
       Principles of Combustion  2005    107.61     9780471046899
       An Introduction to Comb  2011    193.99     9780073380193  
       Guide to Fortran               2009     71.95     9781848825420
       Modern Fortran Explain     2011    100.00     9780199601417
       Introduction to Program    2012    200.00     9780857292322
 
Je ne demande pas une réponse toute faite, mais qu'on m"explique si possible comment m'y prendre  :jap:  
Merci

mood
Publicité
Posté le 04-01-2013 à 15:08:25  profilanswer
 

n°2170129
pascal22
Posté le 07-01-2013 à 16:47:35  profilanswer
 

C'est quelle école qui enseigne Fortran ?
 
open ne fait que ouvrir l'accès au fichier. Après il faut lire le dit fichier ligne par ligne.
 


        open(newunit=myfile, file="file.dat", iostat=ierr)
        ! newunit c'est du fortran 2003
        ! voir les mots clés form et status qui peuvent être utiles
        if(ierr/=0) then
            print *, 'Error while opening the file: file.dat'
            stop
        end if
 
        ! sauter les 3 première lignes
        ! à faire  
 
        ! construire une boucle pour lire ligne à ligne
        ! il y a plein de façon de faire
        do
            ! ce format ne marche que pour un fomat fixe, j'ai un doute à cause du "up to 25 characters"..
            read(myfile, '(A25, I4, F6.2, I13)', iostat=ierr) title, year, price, isbn
            if (ierr/=0) exit
            ! ligne lue et extraite plus qu'à en faire ce qu'on veut
        end do
 
        close(myfile)


n°2170130
Jill_the_R​eturn
Posté le 07-01-2013 à 16:53:06  profilanswer
 

J'ai changé mon program  
 

Code :
  1. program dat
  2.     implicit none
  3.     character (len=25) :: Name
  4.     character (len=13) :: ISBN
  5.     integer :: i, publish_year
  6.     real :: price
  7.     open(unit=10, file="homework_6.dat", status="old", action="readwrite" )
  8.     open(unit=11, file="output_hw6.dat" )
  9.     !Comment: these below 3 lines are for skipping 3 heading your input
  10.     read(10,*)
  11.     read(10,*)
  12.     read(10,*)
  13.     do i=1, 10
  14.     read (10,*) Name, publish_year, price, ISBN
  15.     write (11,1) Name, publish_year, price, ISBN
  16.     1 format(a25,2x,i4,2x,f3.2,2x,a13)
  17.     end do
  18.     close(unit=10)
  19.     end program dat


 
Mais j'ai toujours une erreur pour la ligne 14
 
ERROR 52, invalid character in field DAT - in file homework.f95 at line 14 [+01b3]
 
Je vais essayer ce que tu me proposes


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  Divers

  Programmation avec Fortran ?

 

Sujets relatifs
AIDE A LA PROGRAMMATIONle programmation en c
Aide programmation SIEMENS LOGOProgrammation d'un convertisseur décimal en binaire
Python - Programmation - SoucisProgrammation android
Programmation caméra ip sur internetProgrammation en fortran
qui s'y connait en programmation MPI + Fortran 90Programmation Fortran sous Linux (g77)
Plus de sujets relatifs à : Programmation avec Fortran ?


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR