-2

My question is about converting Fortran to Python language but I couldn't understand the working principle of this part of code. How can I rewrite the code in Python and which statement should I use instead of do if then write statement ?

#FOR GEAR CONVEX SIDE I = l, FOR GEAR CONCAVE SIDE I = 2.

DO 99999 I=1,2
IF(I .EQ. 1)THEN
WRITE (72,*)'GEAR CONVEX SIDE'
DLTA=DLTX
M21PRM=M21XPR
AXIL=AXILX
ELSE
WRITE(72,*)'GEAR CONCAVE SIDE'
DLTA=DLTV
M21PRM=M21VPR
END IF
WRITE (72, *)

AXIA=DEF/(AXIL*AXIL)
#CALCULATE GEAR BLADE ANGLE


IF(I .EQ. 2)THEN
PSIG=180. D00*CNST-PSIG
END IF
CSPSIG=DCOS(PSIG)
SNPSIG=DSIN(PSIG)
CTPSIG=CSPSIG/SNPSIG

##CALCULATE CUTTER TIP RADIUS

IF(I .EQ. 1)THEN
RG = (ADIA-W)/2.DO0
ELSE
RG = (ADIA+W)/2.D00
END IF

It is just a part of the main code and I couldn't understand the DO 9999 i=1,2 section and the following code (the relation of if, then and write).

can23
  • 23
  • 2
  • 1
    Any reason this is tagged Javascript then? – Keith Feb 04 '18 at 22:10
  • please make the question more clear, what are you trying to achieve with the code? – user2305193 Feb 04 '18 at 22:21
  • 1
    DO I=1,2 is a loop in Fortran 77. 99999 is a label - look for it near some CONTINUE statement, it denotes the end of the loop block. Everything between DO and CONTINUE is inside the loop. – Alex Dubrovsky Feb 04 '18 at 22:35
  • this code had been written in 1977 for tooth contact analysis of spiral bevel gear and if i understand the code i will use it with my school project it is just a part of the main code and i couldnt understand the " do 9999 i=1,2 " section and continuing process of code(if then write relation) – can23 Feb 04 '18 at 22:37

1 Answers1

1

Mother of god, it's Fortran 77. I feel your pain.

DO 99999 I=1,2
IF(I .EQ. 1)THEN
WRITE (72,*)'GEAR CONVEX SIDE'
.
.
.
IF(I .EQ. 2)THEN
.
.

is similar to

for i in [1, 2]:
    if i == 1:
        print "GEAR CONVEX SIDE"
        .
        .
    if i == 2:
        .
        .

As far as I understand this part of Fortran code, everything apart from for loop line has to be indented.

If you are writing to file, as WRITE(72, *) might suggest, then you need to open a file before entering the loop and then write to it instead of just using print, something like this:

file = open("filename", "w")
for ...:
    if ...:
        file.write(" GEAR CONVEX SIDE")
    .
    .
    .
Alex Dubrovsky
  • 240
  • 4
  • 14
  • Is Python's print behaving as writing to the Fortran's unit 72? – francescalus Feb 04 '18 at 22:44
  • 1
    And note that it's likely needing `" GEAR CONVEX SIDE"`. With that leading space. – francescalus Feb 04 '18 at 22:45
  • @francescalus - I fixed the answer, thanks for clarification. – Alex Dubrovsky Feb 04 '18 at 23:01
  • i guess the same way with you Alex it relates the print behaviour thank you :) – can23 Feb 04 '18 at 23:02
  • and one more question what does this means ? "PSIG=180. D00*CNST-PSIG" its just a mathematical formula like this X=180*CNST-PSIG ? – can23 Feb 04 '18 at 23:13
  • @can23, I assume it's some angle transformation between convex and concave sides, because `PSIG` is later used in `DCOS` and `DSIN` (cosine and sine functions for double precision calculations, IIRC). Gears are not really my field :) I had a 5000 lines long Fortran 77 CFD code in my Ph.D., inherited from my adviser. I still have nightmares about it. – Alex Dubrovsky Feb 04 '18 at 23:22
  • yes its like angle transformation thank you again :) – can23 Feb 04 '18 at 23:48