A voir également:
- [FORTRAN]lecture de fichier
- Fichier rar - Guide
- Comment réduire la taille d'un fichier - Guide
- Comment ouvrir un fichier epub ? - Guide
- Ouvrir fichier .bin - Guide
- Fichier iso - Guide
4 réponses
PPBoyington
Messages postés
2011
Date d'inscription
mercredi 21 novembre 2007
Statut
Membre
Dernière intervention
22 mai 2012
402
30 mai 2008 à 11:42
30 mai 2008 à 11:42
Le FOrtran c'est tres tres loin pour moi mais je me demande si après avoir compté les enregistrements il ne faudrait pas fermer le fichier et le reouvrir, l'ordre read(12,*) de la seconde boucle arrivant apès un eof
cchristian
Messages postés
921
Date d'inscription
lundi 21 janvier 2008
Statut
Membre
Dernière intervention
6 mars 2012
131
30 mai 2008 à 12:49
30 mai 2008 à 12:49
Bonjour,
Essaie en spécifiant au niveau de l'ordre open: FORM=UNFORMATTED. FORMATTED est pris par défaut.
Essaie en spécifiant au niveau de l'ordre open: FORM=UNFORMATTED. FORMATTED est pris par défaut.
je vous remercie de m'avoir répondu...j'ai résolu le pb.. mon programme marche!
et désolé si ma question paraissait naïve.. je débute en fortran...
bonne semaine à tous
voici la correction :
open(unit = 12, file = 'xko.dat', status = 'old',iostat = ok)
if(ok /= 0) then
write(*,*) 'erreur 1 fichier xko.dat'
stop
end if
do while(ok == 0) !boucle pour compter le nombre de ligne du fichier
read(12,*,iostat = ok)
if (ok == 0) ligne = ligne + 1
end do
write(*,*) 'nombre de ligne: ', ligne
rewind(unit=12,iostat=ok) !repositionnement au début du fichier en lecture
if(ok /= 0) then
write(*,*) 'erreur 2 fichier xko.dat'
stop
end if
do i = 1, ligne
read(12,*,iostat = ok) u(i),v(i)
!write(*,*) u(i),v(i)
end do
close(12)
et désolé si ma question paraissait naïve.. je débute en fortran...
bonne semaine à tous
voici la correction :
open(unit = 12, file = 'xko.dat', status = 'old',iostat = ok)
if(ok /= 0) then
write(*,*) 'erreur 1 fichier xko.dat'
stop
end if
do while(ok == 0) !boucle pour compter le nombre de ligne du fichier
read(12,*,iostat = ok)
if (ok == 0) ligne = ligne + 1
end do
write(*,*) 'nombre de ligne: ', ligne
rewind(unit=12,iostat=ok) !repositionnement au début du fichier en lecture
if(ok /= 0) then
write(*,*) 'erreur 2 fichier xko.dat'
stop
end if
do i = 1, ligne
read(12,*,iostat = ok) u(i),v(i)
!write(*,*) u(i),v(i)
end do
close(12)
cchristian
Messages postés
921
Date d'inscription
lundi 21 janvier 2008
Statut
Membre
Dernière intervention
6 mars 2012
131
2 juin 2008 à 11:42
2 juin 2008 à 11:42
Bonjour,
Merci pour le retour, bon courage,
Merci pour le retour, bon courage,
Purpose
Statement Associates a unit number with an external file or device.
Syntax
OPEN ([UNIT=] unit [ , [ , IOSTAT=iostat] [ , STATUS=status] )
IOSTAT sets the value of iostat to-1 if end-of-file is encountered, to -2 if an end-of-record is encountered, and to the run-time error number (a positive integer) if an error occurs. (See Run-time Error Messages for a list of error numbers and their meaning.) If none of these conditions occurs, iostat is set to 0. IOSTAT can be used with any I/O statement except PRINT.
iostat
(Output) Default integer (INTEGER(4) unless changed by the user). Zero if no error occurs, a negative integer if an end-of-file record is encountered, or the number of the error message. See Errors, End-of-File and End-of-Record Handling (IOSTAT=, ERR=, END=, EOR=) in the Programmer's Guide.
Statement Associates a unit number with an external file or device.
Syntax
OPEN ([UNIT=] unit [ , [ , IOSTAT=iostat] [ , STATUS=status] )
IOSTAT sets the value of iostat to-1 if end-of-file is encountered, to -2 if an end-of-record is encountered, and to the run-time error number (a positive integer) if an error occurs. (See Run-time Error Messages for a list of error numbers and their meaning.) If none of these conditions occurs, iostat is set to 0. IOSTAT can be used with any I/O statement except PRINT.
iostat
(Output) Default integer (INTEGER(4) unless changed by the user). Zero if no error occurs, a negative integer if an end-of-file record is encountered, or the number of the error message. See Errors, End-of-File and End-of-Record Handling (IOSTAT=, ERR=, END=, EOR=) in the Programmer's Guide.
30 mai 2008 à 11:49
open(unit = 12, file = 'xko.dat', status = 'old',iostat = ok)
if(ok /= 0) then
write(*,*) 'erreur 1 fichier xko.dat'
stop
end if
do while(ok == 0) !boucle pour compter le nombre de ligne du fichier
read(12,*,iostat = ok)
if (ok == 0) ligne = ligne + 1
end do
write(*,*) 'nombre de ligne: ', ligne
rewind(unit=12,iostat=ok) !repositionnement au début du fichier en lecture
if(ok /= 0) then
write(*,*) 'erreur 2 fichier xko.dat'
stop
end if
read(12,*)
do i = 1, ligne ,1
write(*,*) u(i),v(i)
end do
close(12)
ca me donne plus le message d'erreur par contre j'obtiens des valeurs byzarre du genre :
134513633 -1.266659408805960E-039
-1302241474 3.646994461465999E-314
0 -5.114562042769608E-039
0 -4.310800876104207E-002
0 -4.823495536104870E-039
0 -5.114304287766659E-039
0 -4.556574190475721E-039
1 0.00000000000000
.....
30 mai 2008 à 12:49
do i = 1, ligne ,1
write(*,*) u(i),v(i)
end do
Tu lis sur le fichier met ne met le résultat nulle part, puis tu affiche des variables sur la consolen qu'on sait même pas où elles ont été initialisé. Du coup, ça ne me surprend pas que tu écrive n'importe quoi.
6 nov. 2013 à 10:57