! This Fortran code is intended to be called from another language
!  In this sample, that is Borland Delphi
! There are three routines in this file:
!    Function FortFunInt (integer*4 IArg)
!        returns 2xIarg as Integer*4
!    Function FortFunSingle (real*4 FArg)
!		 returns SQRT(Farg) or 0 if Farg < 0
!    Function FortFunString (string Sarg)
!		 returns a string with the case inverted
!		  The string argument is passed by reference only
!		  and the return argument is returned in hidden 
!		  first and second arguments.
! This project is provided as x86-only

INTEGER*4 Function FortFunInt (iArg)
!DEC$ ATTRIBUTES STDCALL, DLLEXPORT :: FortFunInt
!DEC$ ATTRIBUTES ALIAS : "_fortfunint" :: FortFunInt

integer iArg;

FortFunInt = 2*iArg
return
end function FortFunInt

Real*4 Function FortFunSingle (fArg)
!DEC$ ATTRIBUTES STDCALL, DLLEXPORT :: FortFunSingle
!DEC$ ATTRIBUTES ALIAS : "_fortfunsingle" :: FortFunSingle
Real *4 fArg

if (fArg .le. 0) then
   FortFunSingle = 0
else
   FortFunSingle = SQRT(fArg)
endif
return
end function FortFunSingle

Character *(*) function FortFunString (sArg)
Implicit none
!DEC$ ATTRIBUTES STDCALL, DLLEXPORT :: FortFunString
!DEC$ ATTRIBUTES ALIAS : "_fortfunstring" :: FortFunString
character(255) sArg  !Passed in as a null-terminated string
!DEC$ ATTRIBUTES REFERENCE ::  sArg

Integer lenInput
integer lenOutput
Integer i, j

lenInput = index(sArg, char(0))
lenOutput = len(FortFunString)-1

i = min(leninput, lenoutput)

do j=1, i
	if (sArg(j:j) .le. 'z' .and. sArg(j:j) .gt. 'a') then
	    FortFunString(j:j) = char (ichar(sArg(j:j)) - 32)
	else 
	  if (sArg(j:j) .le. 'Z' .and. sArg(j:j) .gt. 'A') then
	    FortFunString(j:j) = char (ichar(sArg(j:j)) + 32)
	   else
		 FortFunString(j:j) = sArg(j:j)
	   endif
    endif
	
enddo
FortFunString(i+1:i+1) = char(0)
return
end
