Bonjour,

j'ai fait le programme suivant pour lire un fichier de données .dat et modéliser ses composantes. J'aimerais le faire fonctionner quelque soit la taille du tableau, mais je n'y arrive pas : je suis toujours obligé de donner la taille du tableau !
Si quelqu'un avait une idée ! (Je sais qu'en fortran 90 c'est facilement faisable, mais je dois uniquement utiliser le fortran 77...).
Voici le code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
C
C this program gives the linear (average) equation giving the acceleration
C as a function of the voltage :
C
      PROGRAM linearleast
      IMPLICIT NONE
      INTEGER i,c,j,n
      PARAMETER (n=8)
C n is the number of rows in the data file
      REAL A(n,2)     
C A is the matrix in which the datas will be stored
      OPEN (33,FILE='xydata.dat',form='formatted',status='old')
      DO i=1,n
C creation of the matrix A :
         READ (33,*) (A(i,j),j=1,2) 
      END DO
      CALL coef (A,n)
      END
C
      SUBROUTINE coef (D,m)
      IMPLICIT NONE
      INTEGER i,j,m
      REAL D(m,2),c,b,g,E(m),f,a,H(m),k,l
C c is the sum of the accelerations
      c=0
      DO i=1,m
         c=c+D(i,1)
      END DO
C b is the sum of the voltages
      b=0
      DO i=1,m
         b=b+D(i,2)
      END DO
C g is the average coefficient (b/c)
      g=b/c
C E contains the residuals
      DO i=1,m
         E(i)=D(i,2)-g*D(i,1)
      END DO
C H contains the estimated voltages (the estimated Y)
      DO i=1,m
         H(i)=g*D(i,1)+H(i)
      END DO
C k is the sum of the residuals      
      k=0
      DO i=1,m
         k=k+E(i)
      END DO
C l is the average residual
      l=k/m
      PRINT 10, g,l
 10   FORMAT (1X,'THE LINEAR EQUATION IS : Y(X)= ',F6.3,' X + ',F6.3)
      PRINT *,'ORIGINAL     ORIGINAL     ESTIMATED     RESIDUAL'
      PRINT *,'   X            Y             Y '
      DO i=1,m
      PRINT 20, D(i,1),D(i,2),g*D(i,1)+l,E(i)
 20   FORMAT (' ',F6.3,'       ',F6.3,'        ',F6.3,'       ',F6.3)
      END DO
      END

Merci d'avance,
Nulysses