How to Handle Line Truncation in Fortran?

  • Fortran
  • Thread starter LucasCampos
  • Start date
  • Tags
    Fortran Line
In summary, the conversation was about a program that uses more than 72 characters per line and how to compile it using a specific compiler and avoid truncation errors. The code for the program and its various subroutines and functions were also provided.
  • #1
LucasCampos
17
0
I've made a program that uses more than 72 characters per line. When I try to compile it on gfortran, using -ffixed-line-length-n, it returns several errors, all of them derived from a line truncated at the very beggining. How can I compile it or untruncate the line?

The code is as follows

Code:
Program Rotation
Implicit None 
Double Precision dt,ve,mass,radius,height,pmass,vx,vy,area,rad,de,weight,g,t,tmax,ymax,rangmax,inertia,pweight,tet,ar,torque,vymid,vxmid,dy,dx,ax,ay,rang,w
Integer nshow,counter
CALL Opener
CALL Inserter (dt,ve,de,tet,w,mass,radius,height,pmass,nshow)
CALL Calc (ve,vx,vy,mass,radius,area,rad,de,weight,g,t,tmax,ymax,rangmax,inertia,pmass,pweight,counter)
CALL Torq (pweight,tet,ar,inertia,torque)
CALL Velocitymed (vx,vy,ay,ax,t,dt,vymid,vxmid)
CALL Drags (vx,vy,vymid,vxmid,dy,dx,area,ax,ay,weight,mass)
CALL Euler (radius,mass,area,weight,vxmid,vymid,vy,vx,dy,dx,ay,ax,t,dt,height,rang,rangmax,tmax,ymax,ar,w,tet,inertia,torque,pweight,counter,nshow)
CALL print_table (vx,vy,t,ax,ay,dx,dy,height,rang,tet,w,ar)
End

Subroutine inserter (dt,ve,de,tet,w,mass,radius,height,pmass,nshow)
Implicit None 
Double Precision dt,ve,de,tet,w,mass,radius,height,pmass
Integer nshow
Write (*,*) 'Insert time step(s)'
Read (*,*) dt
Write (*,*) 'Insert initial height(m)'
Read (*,*) height
Write (*,*) 'Insert initial translational speed (m/s)'
Read (*,*)ve
Write (*,*) "Insert inital translational speed's angle to the ground (degrees)"
Read (*,*)de
Write (*,*) 'Insert initial angular space (rad)'
Read (*,*) tet
Write (*,*) 'Insert initial angular speed (rad/s)'
Read (*,*) w
Write (*,*) "Insert disk's mass(kg)"
Read (*,*)mass
Write (*,*) "Insert point's mass(kg)"
Read(*,*) pmass
Write (*,*) 'Insert radius(m)'
Read (*,*)radius
Write (*,*) 'Insert number os steps between output'
Read (*,*)nshow
End

Subroutine Calc (ve,vx,vy,mass,radius,area,rad,de,weight,g,t,tmax,ymax,rangmax,inertia,pmass,pweight,counter)
Implicit None
Double Precision ve,vx,vy,mass,radius,area,rad,de,weight,g,t,tmax,ymax,rangmax,inertia,pmass,pweight
Integer counter
g=-9.8
t=0.0D0
rad=de*0.0174532925
vx=ve*(cos(rad))
vy=ve*(sin(rad))
area=3.141592654*(radius**2)
weight=mass*g
pweight=pmass*g
counter = 0
ymax = -5000
tmax = -5000
rangmax = -5000
inertia=(pmass+mass)*(radius**2)*0.66
END

Subroutine Torq (pweight,tet,ar,inertia,torque)
Implicit None
Double Precision pweight,tet,ar,inertia,torque
torque=pweight*cos(tet)
ar=torque/inertia
End

Subroutine Velocitymed (vx,vy,ay,ax,t,dt,vymid,vxmid)
Implicit None
Double Precision vx,vy,ay,ax,t,dt,vymid,vxmid
IF (t .EQ. 0.0D0) vymid = vy
IF (t .EQ. 0.0D0) vxmid = vx
IF (t .NE. 0.0D0) vymid = vy+(ay*(dt/2))
IF (t .NE. 0.0D0) vxmid = vx+(ax*(dt/2))
END

Subroutine Drags (vx,vy,vymid,vxmid,dy,dx,area,ax,ay,weight,mass)
Implicit None
Double Precision vx,vy,vymid,vxmid,dy,dx,area,ax,ay,weight,mass
IF (vy .LT. 0.0D0) dy=(vymid**2)*area*0.5D0
IF (vy .GT. 0.0D0) dy=-(vymid**2)*area*0.5D0
IF (vx .LT. 0.0D0) dx=(vxmid**2)*area*0.5D0
IF (vx .GT. 0.0D0) dx=-(vxmid**2)*area*0.5D0
ay=(dy+weight)/mass
ax=dx/mass
END

Subroutine Euler (radius,mass,area,weight,vxmid,vymid,vy,vx,dy,dx,ay,ax,t,dt,height,rang,rangmax,tmax,ymax,ar,w,tet,inertia,torque,pweight,counter,nshow)
Implicit None
Double Precision radius,mass,area,weight,vxmid,vymid,vy,vx,dy,dx,ay,ax,t,dt,height,rang,rangmax,tmax,ymax,ar,w,tet,inertia,torque,pweight
Integer counter,nshow
100 IF (mod(counter,nshow) .EQ. 0) Call print_table (vx,vy,t,ax,ay,dx,dy,height,rang,tet,w,ar,radius)
Call Euler_Disk (mass,area,weight,vxmid,vymid,vy,vx,dy,dx,ay,ax,t,dt,height,rang,counter,nshow)
Call Euler_pointr (ar,w,tet,dt,inertia,torque,pweight)
counter = counter + 1
IF (height .GT. ymax) tmax=t
IF (height .GT. ymax) rangmax=rang
IF (height .GT. ymax) ymax=height
IF (height .LT. 0.0D0) Go to 200
t=t+dt
Go to 100
200 WRITE(11,*) tmax,ymax
End

Subroutine Euler_pointr (ar,w,tet,dt,inertia,torque,pweight)
Implicit None
Double Precision ar,w,tet,dt,inertia,torque,pweight
Call Torq (pweight,tet,ar,inertia,torque)
w=w+(ar*dt)
tet=tet+(w*dt)
End

Subroutine Euler_Disk (mass,area,weight,vxmid,vymid,vy,vx,dy,dx,ay,ax,t,dt,height,rang,rangmax,tmax,ymax,counter,nshow)
Double Precision mass,area,weight,vxmid,vymid,vy,vx,dy,dx,ay,ax,t,dt,height,rang,rangmax,tmax,ymax
Integer counter,nshow
CALL Velocitymed (vx,vy,ay,ax,t,dt,vymid,vxmid)
CALL Drags (vx,vy,vymid,vxmid,dy,dx,area,ax,ay,weight,mass)
vy=vy+(ay*dt)
vx=vx+(ax*dt)
height=height+(vymid*dt)
rang=rang+(vxmid*dt)
End

Subroutine print_table (vx,vy,t,ax,ay,dx,dy,height,rang,tet,w,ar,radius)
Implicit None
Double Precision vx,vy,t,ax,ay,dx,dy,height,rang,tet,w,ar,radius
WRITE (1,*) t,vx
WRITE (2,*) t,vy
WRITE (3,*) t,ax
WRITE (4,*) t,ay
WRITE (12,*) t,dx
WRITE (13,*) t,dy
WRITE (14,*) t,height
WRITE (15,*) rang,height
WRITE (16,*) t,rang
WRITE (17,*) t,tet
WRITE (18,*) t,w
WRITE (19,*) t,ar
Write (20,*) t, (height+(radius*sin(tet)))
Write (21,*) (rang+(radius*cos(tet))), (height+(radius*sin(tet)))
Write (22,*) t, (rang+(radius*cos(tet)))
END

Subroutine Opener
OPEN (Unit=1,FILE="vx.dat")
OPEN (Unit=2,FILE="vy.dat")
OPEN (Unit=3,FILE="ax.dat")
OPEN (Unit=4,FILE="ay.dat")
OPEN (Unit=11,FILE="heightmax.dat")
OPEN (Unit=12,FILE="dragx.dat")
OPEN (Unit=13,FILE="dragy.dat")
OPEN (Unit=14,FILE="height.dat")
OPEN (Unit=15,FILE="rangeheight.dat")
OPEN (Unit=16,FILE="range.dat")
OPEN (Unit=17,FILE="angle.dat")
OPEN (Unit=18,FILE="rspeed.dat")
OPEN (Unit=19,FILE="rotacce.dat")
OPEN (Unit=20,FILE="point's height.dat")
OPEN (Unit=21,FILE="Full.dat")
OPEN (Unit=22,File="point's range.dat")
END
 
Technology news on Phys.org
  • #2
You can just use a line continuation, e.g.

Code:
Program Rotation
Implicit None 
Double Precision dt,ve,mass,radius,height,pmass,vx,vy,area,rad,&
de,weight,g,t,tmax,ymax,rangmax,inertia,pweight,tet,ar,torque,&
vymid,vxmid,dy,dx,ax,ay,rang,w
Integer nshow,counter
CALL Opener
CALL Inserter (dt,ve,de,tet,w,mass,radius,height,pmass,nshow)
CALL Calc (ve,vx,vy,mass,radius,area,rad,de,weight,g,t,tmax,ymax,rangmax,&
inertia,pmass,pweight,counter)

Note the ampersands. As long as your in Fortran 90+, you don't have to worry about special characters on the following line, just a single ampersand will work.
 

1. What is "Line Truncation" in Fortran?

Line truncation in Fortran refers to the process of limiting the number of characters that can be used in a single line of code. This is typically done to improve readability and to adhere to coding conventions.

2. How is line truncation achieved in Fortran?

In Fortran, line truncation is achieved by using a specific character (usually the ampersand symbol "&") at the end of a line to indicate that the code continues on the next line. This allows for longer code lines to be broken into multiple lines without affecting the functionality of the code.

3. What are the benefits of line truncation in Fortran?

Line truncation in Fortran can improve the readability and maintainability of code by breaking long lines into shorter, more manageable segments. It also helps to adhere to coding conventions and standards, making it easier for other programmers to understand and modify the code.

4. Are there any limitations to line truncation in Fortran?

Yes, there are some limitations to line truncation in Fortran. One limitation is that the ampersand character cannot be used inside a character string or comment. Also, some compilers may have a limit on the number of characters that can be used in a single line, so it is important to check the compiler's documentation for any restrictions.

5. Can line truncation affect the performance of Fortran code?

No, line truncation does not have any impact on the performance of Fortran code. It is purely a formatting technique and does not affect the execution of the code in any way.

Similar threads

  • Programming and Computer Science
Replies
4
Views
1K
  • Special and General Relativity
Replies
11
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
18
Views
2K
  • Mechanics
Replies
4
Views
4K
  • Introductory Physics Homework Help
Replies
4
Views
3K
  • Introductory Physics Homework Help
Replies
2
Views
3K
  • Introductory Physics Homework Help
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
3K
  • Computing and Technology
Replies
6
Views
2K
Back
Top