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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADA to Fortran convertion

Status
Not open for further replies.

java12

Programmer
Dec 4, 2009
1
US
Hi Friends,

I have an ADA function that needs to be converted to Fortran.

function Sumer (Mat: in Mat_Type) return Float is
Sum: Float := 0.0;
begin
for Row in Mat 'range (1) loop
for col in Mat 'range(2) loop
Sum := Sum + Mat(Row, Col);
end loop;
end loop;
return Sum;
end Sumer;
 
Depends on which version of Fortran you're using. F90 onwards, it would be
Code:
real*4 function sumer(mat)
   real*4:: mat(*,*)

   sumer = sum(sum(mat,1),1)
end
If you want something more long winded
Code:
real*4 function sumer(mat)
   real*4:: mat(*,*)
   integer:: ii, jj

   sumer = 0.0
   do ii = 1, ubound(mat,1)
      do jj = 1, ubound(mat,2)
         sumer = sumer + mat(ii,jj)
      enddo
   enddo
end
If you want it in F77, then you'll have to pass the dimensions into the function.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top