INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Derivation

RE: Derivation

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 

RE: Derivation

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 

RE: Derivation

(OP)
Hi, thank you for the answer
This program run but i have no results in the file 40

RE: Derivation

I tried it yesterday,
created input file MP with 3 example records of data and both output files resultats and deriv were written

RE: Derivation

(OP)
I tried with 3 exemples of data file MP and i have no results in Deriv file???

RE: Derivation

Quote (wassim2015)


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 

RE: Derivation

(OP)
But that does not run with N>100, this is the problem

RE: Derivation

Quote (wassim2015 )


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 ?

RE: Derivation

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 

RE: Derivation

I overseen I overlooked ;)

RE: Derivation

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 --> fortran

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

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close