Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Derivation

Status
Not open for further replies.
the error was in opening unit 30 in a loop and in the defining formats for writing.

I tried to correct it - see here and compare it with the source you posted
Code:
program exemple
implicit none
INTEGER::I
integer,parameter::N=3
real,dimension(N)::beta,gamma,H,dH


OPEN(unit=10,file='MP')
open(unit=30,file='resultats')
open(unit=40,file='deriv')
WRITE(30,200)'beta','gamma','H','dH'

DO I=1,N
  READ(10,*)beta(I),gamma(I)
  H(I)=0
  H(I)=H(I)+(beta(I)*sin(gamma(I)))
  WRITE(30,300)beta(I),gamma(I),H(I)
  write(*,*) beta(I),gamma(I),H(I) 
enddo

DO I=1,N
  dH(I)=0
  dH(I)=(H(I+1)-H(I-1))/(beta(I+1)-beta(I-1))
enddo

do I=1,N
  WRITE(40,400)beta(I),gamma(I),H(I),dH(I)
enddo 

CLOSE(10)
close(30)
close(40)

200 format(a10, a10, a10, a10)
300 format(f10.2,f10.2,f10.2)
400 format(f10.2,f10.2,f10.2,f10.2)
end program exemple
 
form source I posted above delete this line, which I added for debugging:
Code:
write(*,*) beta(I),gamma(I),H(I)

and set back the value of N from
Code:
integer,parameter::N=3
to the number of lines in your data file - it was:
Code:
integer,parameter::N=144
 
Hi, thank you for the answer
This program run but i have no results in the file 40
 
I tried it yesterday,
created input file MP with 3 example records of data and both output files resultats and deriv were written
 
I tried with 3 exemples of data file MP and i have no results in Deriv file???
 
wassim2015 said:
I tried with 3 exemples of data file MP and i have no results in Deriv file???
Then you must have done something wrong.

I created input file:
MP
Code:
0.1		0.5
0.2 	1
0.3		1.5

then runned the corrected Text1.f90:
Code:
mikrom@mikrom-Lenovo-S500 ~/Downloads $ gfortran Text1.f90 -o Text1 
mikrom@mikrom-Lenovo-S500 ~/Downloads $ ./Text1
which created 2 output files:
resultats
Code:
beta     gamma         H        dH
0.10      0.50      0.05
0.20      1.00      0.17
0.30      1.50      0.30

deriv
Code:
0.10      0.50      0.05      0.84
0.20      1.00      0.17      1.26
0.30      1.50      0.30      0.84

I use this program source:
Text1.f90
Code:
program exemple
implicit none
INTEGER::I
integer,parameter::N=3
real,dimension(N)::beta,gamma,H,dH


OPEN(unit=10,file='MP')
open(unit=30,file='resultats')
open(unit=40,file='deriv')
WRITE(30,200)'beta','gamma','H','dH'

DO I=1,N
  READ(10,*)beta(I),gamma(I)
  H(I)=0
  H(I)=H(I)+(beta(I)*sin(gamma(I)))
  WRITE(30,300)beta(I),gamma(I),H(I)
enddo

DO I=1,N
  dH(I)=0
  dH(I)=(H(I+1)-H(I-1))/(beta(I+1)-beta(I-1))
enddo

do I=1,N
  WRITE(40,400)beta(I),gamma(I),H(I),dH(I)
enddo 

CLOSE(10)
close(30)
close(40)

200 format(a10, a10, a10, a10)
300 format(f10.2,f10.2,f10.2)
400 format(f10.2,f10.2,f10.2,f10.2)
end program exemple
 
wassim2015 said:
But that does not run with N>100, this is the problem
And how many lines of input you have ? Maybe it could be an array size problem.

And does it run for you with the input file (i.E.) with 3 lines I posted ?
 
I overseen, that you are using double step formula, so the second loop should go from 2 to N-1, like you originally have
Code:
do I=2,N-1
  dH(I)=0
  dH(I)=(H(I+1)-H(I-1))/(beta(I+1)-beta(I-1))
  write(40,400)beta(I),gamma(I),H(I),dH(I)
enddo
 
In the file MP.txt you posted there are 144 lines, BUT first two are not relevant
Code:
Pd110  HTDA-CRANKING M.IMADALOU COR SEP.2014"""""""
110,46
   0.00  0.00   -929.18598   71.62987    0.00000   72.69126    0.17632    0.17632    0.00000
   0.05  0.00   -929.61269   75.93454    0.00000   75.95358    0.72401    0.72401    0.00000
...
...
So you have only 142 data records

I corrected your code
Code:
...
open(unit=10,file='MP.txt')
...
! header
read(10,*)
read(10,*)
do I=1,N
  ...
enddo
and got results written in resultats and deriv

 
 http://files.engineering.com/getfile.aspx?folder=7a3ad2d5-905b-4c30-b020-806d94c624e7&file=resultats
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top