# Fortran coding do loop

1. Sep 5, 2011

### shei7141

Can some1 kindly help me understand the following code, I am trying to translate the following code in VBA:

FFLC = FLC .......i understand this part
ANGLE=PI/6 !Suppose 30 Degrees .......i understand this part
Do 21800 I=i,5 .......Don't understand this
FLC=FFLC-COS(ANGLE)*NDIA
FLE=SQRT(FLB*FLB+FLC*FLC) .......i understand this part
21800 ANGLE=ATAN2(FLC,FLB).......i understand this part
if (R.NE.o.)D=R/2.+NDIA/2.......i understand this part
FLCUT = ........ .......i understand this part
LE=IFIX(FLE).......Don't understand this

My answer for FLCUT is 2387 when using the 30 degree angle but fortran result 2397 (after using the iteration which I dont understand)

Regards

2. Sep 5, 2011

### stallionx

FFLC = FLC .......i understand this part
ANGLE=PI/6 !Suppose 30 Degrees .......i understand this part

Do 21800 I=i,5 .......Don't understand this --> execute lines until line number 21800, from I=i to I=5 ; that is 5-i+1 iterations

FLC=FFLC-COS(ANGLE)*NDIA
FLE=SQRT(FLB*FLB+FLC*FLC) .......i understand this part
21800 ANGLE=ATAN2(FLC,FLB).......i understand this part
if (R.NE.o.)D=R/2.+NDIA/2.......i understand this part
FLCUT = ........ .......i understand this part
LE=IFIX(FLE).......Don't understand this-->IFIX must be some function / subroutine otherwise it would be taking dimension of a Real

My answer for FLCUT is 2387 when using the 30 degree angle but fortran result 2397 (after using the iteration which I dont understand)

3. Sep 5, 2011

### shei7141

thanks mate,

in above equation, I understand that the iteration required to refine the angle. it is starting with 30 degrees angle and iterating it (which I dont understand how).... could you provide me a break down of iteration. I am totally new with fortran. I'll appreciate if you could take me through the step by step and tell me what would be the angle after iterating the equation.

Thanks

4. Sep 5, 2011

### stallionx

Hi :)

You are welcome.

Can you post the whole program code

PROGRAM xxxx
.
.
.
STOP
END.

The dots.

5. Sep 5, 2011

### shei7141

Fflc=flc
angle=pi/6 !suppose 30 degrees
do 21800 i=1,5
flc=fflc-cos(angle)*ndia
fle=sqrt(flb*flb+flc*flc)
21800 angle =atan2(flc,flb)
if(r.ne.0) d=r/2+ndia/2
flcut=fla+fle-2*(d+ndia/2)*tan(angle/2)+d*angle
le=ifix(fle)
return

where fla = 1865
flb = 145
flc540
r=80
ndia=16

fle should have been 555 (after iteration) but when i ran it with 30 degree my answer was 545.

I am just wondering how should fle be 555 after.

Pls help

6. Sep 5, 2011

### shei7141

Fflc=flc
angle=pi/6 !suppose 30 degrees
do 21800 i=1,5
flc=fflc-cos(angle)*ndia
fle=sqrt(flb*flb+flc*flc)
21800 angle =atan2(flc,flb)
if(r.ne.0) d=r/2+ndia/2
flcut=fla+fle-2*(d+ndia/2)*tan(angle/2)+d*angle
le=ifix(fle)
return

where fla = 1865
flb = 145
flc540
r=80
ndia=16

fle should have been 555 (after iteration) but when i ran it with 30 degree my answer was 545.

I am just wondering how should fle be 555 after.

Pls help

7. Sep 5, 2011

### stallionx

I do not t see the entire program , maybe you should manually enter Pi/6 in radians which is appr. =

0,523598776

8. Sep 5, 2011

### shei7141

i have tried pi/6 and which results in FLE = 545 but program is resulting in 555. This diffirence is likely due to this iteration

9. Sep 5, 2011

### stallionx

It also could be due to declaration mismatch, try to declare all your values Double Precision or Real and and when doing operations inside the code, use real number formats for numbers
, eg : Pi/6=make it Pi/6.0 where Pi should be declared a REAL or D.P:

10. Sep 5, 2011

### shei7141

and i am trying to understand what does Do loop is changing in entire process

11. Sep 5, 2011

### shei7141

please help . . .. i dont understand this.... all of my work is waiting at this bugger

12. Sep 5, 2011

### stallionx

Sir/Ma'am, Personally , I need to see the entire code. Otherwise, I am sorry I can not offer any help :(

13. Sep 5, 2011

### shei7141

btw I am a female ..

this is the entire code..... to calculate the bar length of a F shaped steel bar.....

there are 99 other codes like these for other types of the shapes but they are similar. so somehow if we figure this code out, will mean all sorted ......

the only place I see Do loop is changing is the angle of the bar. the program is using 30 degree angle as a starting point and than refining the angle using the iteration. And I cant really understand how exactly the do loop is refining the angle....

14. Sep 5, 2011

### stallionx

Ok I'll do the first and second iterations, you do others

flc=540-8*sqrt(3)

flb = 145 in all iterations

atan2(flc,flb)= atan of the angle of (540-8*sqrt(3) ) + 145 j

2nd iteration

flc=526.1436-sqrt(3)*8
flb=145

atan2(512.2902 , 145)

angle at second iteration becomes angle= 0.2758 rads =15.8 degrees

Something like that

15. Sep 5, 2011

### stallionx

BTW your gender would not matter to me but what we are dealing here is Fortran 90 Language, sorry I only can speak WF77.

Hope you'll find help.

Best Regards.

16. Sep 5, 2011

### shei7141

thank you very for all your help......

I am really really thankful for all your assistance......

I am going to try this now and hope will get the right answers.....

Once again thanks

17. Sep 5, 2011

### shei7141

oh i only mentioned my gender cos you said sir/ madam..... i didn't mean any wrong.... Apology for any inconvenience

18. Sep 5, 2011

### stallionx

My Apologies. I just was being ethical and stuff, I could not think I would cause any misunderstanding. I am Terribly sorry.

Good Luck in the Forum, Lady.

19. Sep 5, 2011

### shei7141

no need to apologize

I am really very thankful for your time and everything

Kindest regards

20. Sep 5, 2011

### gsal

This is what I get with your fortran code:

Code (Text):

fla =  1865.
flb =  145.
flc =  540.
r   =  80.

pi =  3.141592

i =  1
angle=  0.52359873
flc =  526.1436
fle =  545.7583
angle=  1.3018816

i =  2
angle=  1.3018816
flc =  535.749
fle =  555.02435
angle=  1.3064796

i =  3
angle=  1.3064796
flc =  535.82
fle =  555.09283
angle=  1.306513

i =  4
angle=  1.306513
flc =  535.8205
fle =  555.0933
angle=  1.3065132

i =  5
angle=  1.3065132
flc =  535.8205
fle =  555.0933
angle=  1.3065132

flcut =  2397.086

I would like to point out that having 'pi' defined or not does not make that much of a difference after the first iteration...I have opted to defined it, though, since clearly it was intended to be there.