Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
29285 Discussions

question about xcel sample in C:Program FilesIntelCompilerFortran10.0.025samplesMixedLanguageExcel

ssund
Beginner
1,899 Views
I tried to run the example in C:\Program Files\Intel\Compiler\Fortran\10.0.025\samples\MixedLanguage\Excel
and got the following error when I tried to run it in Xcel 2003 (11.8231.8221) SP3
Runtime error!
Program c:\programfiles\microsoft office\office11\excel.exe
R6034 an application has made an attempt to load the C runtime librarys incorrectly.
and when I click OK i get anoter Microsoft visual basic run time error '48' file not found t:\ses\test2\fcall.dll.


0 Kudos
15 Replies
Steven_L_Intel1
Employee
1,899 Views
Did you read the instructions in the Excel file?

I haven't seen the first error before, though...
0 Kudos
ssund
Beginner
1,899 Views
Did you read the instructions in the Excel file?

I haven't seen the first error before, though...

Yes I changed the path which shows up in the second error. I looked on the web and found that if I use
ifort /dll FortranDLL.f90 /MT it works OK. My question now is what is really needed in the fortran

subroutine FortranCall (r1, num)

!DEC$ ATTRIBUTES DLLEXPORT, STDCALL, REFERENCE, ALIAS:"FortranCall" :: FortranCall

integer, intent(in) :: r1

character(10), intent(out) :: num

!DEC$ ATTRIBUTES REFERENCE :: num

num = ''

write (num,'(i0)') r1 * 2

return

end subroutine FortranCall
My fortran is

c234567

subroutine SUNDCALC(x, y,i,res)

!DEC$ ATTRIBUTES DLLEXPORT, STDCALL, REFERENCE, ALIAS:"SUNDCALC" :: SUNDCALC

c !DEC$ ATTRIBUTES REFERENCE :: num

real*8 x,y

integer i

real*8 res

if(i.eq.0)then

res=x+y

else

res=x-y

endif

return

end
which doesn't work.

0 Kudos
Steven_L_Intel1
Employee
1,899 Views
What doesn't work? I don't see a problem in your Fortran code, as long as the Excel declaration matches.
0 Kudos
ssund
Beginner
1,899 Views
What doesn't work? I don't see a problem in your Fortran code, as long as the Excel declaration matches.
Lionel,
I am building the fortran in F77 and no matter what I do I get the error in excel. I have documented the error and would like to send you the fortran77 and the 2003 excel file. What I want to do is use the Fortran77 calculation module which transfers 2 real values in and returns 1 real back. If I have to do it in Fortran90 that will be OK but I am not that fluent in Fortran 90. So can I email you my simple code and xcel or get another examplethat does what I want?


0 Kudos
Steven_L_Intel1
Employee
1,899 Views
No, please do not send me your code. If you want to attach a zip file of your solution folder here, you can. That will allow others to take a look. I don't quite understand your remarks about Fortran 77 and Fortran 90. If you are using Intel Fortran, that is a single Fortran 95 compiler. Maybe you're referring to fixed-form source, but that doesn't change anything regarding how you would implement this task.
0 Kudos
ssund
Beginner
1,899 Views
No, please do not send me your code. If you want to attach a zip file of your solution folder here, you can. That will allow others to take a look. I don't quite understand your remarks about Fortran 77 and Fortran 90. If you are using Intel Fortran, that is a single Fortran 95 compiler. Maybe you're referring to fixed-form source, but that doesn't change anything regarding how you would implement this task.

Well here goes.
I am attaching the excel file with the VBA code included which references the sundcalc.for program and the fortran files in a zip file.

Option Explicit
Public Declare Sub SUNDCALC Lib "D:Documents and Settingse039373My DocumentsTZtestsundcalc.dll" _
(ByRef x As Double, ByRef y As Double, ByRef i As Long, ByRef res As Double)

and

Private Sub CommandButton1_Click()

Dim x As Double
Dim y As Double
Dim i As Long
Dim res As Double

x = Range("var1").Value
y = Range("var2").Value
i = Range("flag").Value

Call SUNDCALC(x, y, i, res)

Range("result").Value = res

End Sub



I also included what I think should be the reqired

cDEC$ ATTRIBUTES DLLEXPORT, STDCALL, REFERENCE, ALIAS:"SUNDCALC" :: SUNDCALC to the
fortran file. sundcalc.for

What I am trying todo is get this simple example to work. It takes two real numbers X1 and X2 and an integer flag as input. Based on an integer flag the subroutineadds the two reals or subtracts the two reals and then returns the result.
I have built this in Compaq VF 6.x and it works fine. However, Compaq VF requires a .def file which I included in the attached zip file.

Also, I found that for the example in the included samples that comes with intel Visual fortran to make it work I must compile using
ifort /dll Fcall/MT to make the sample work. I used this compilation command to compile sundcalc.

I also noticed that the sample creates the following files .dll, .exp,.lib,*obj
but my program creates .dll,.dll.manifest, and .obj.

Steve

0 Kudos
Steven_L_Intel1
Employee
1,899 Views
You did not follow all the steps for attaching files. You need to go back into Add Files, click on the folder, click on the file and then click Add as Attachment.

In version 10.0 (unsupported), there is just a Visual Studio solution for the Excel sample. In version 11 a build.bat file is also provided illustrating building from the command line.

That you do not get a .exp and .lib indicates that you have not named a routine in a DLLEXPORT directive.
0 Kudos
anthonyrichards
New Contributor III
1,899 Views
I use CVF 6.6C and it works OK for me. I just compile the following into a SUNDCALC.DLL :

subroutine SUNDCALC(x, y,i,res)
!DEC$ ATTRIBUTES DLLEXPORT, STDCALL, REFERENCE, ALIAS:"SUNDCALC" :: SUNDCALC
!DEC$ ATTRIBUTES REFERENCE :: x,y,i,res
real*8 x,y
integer i
real*8 res
if(i.eq.0)then
res=x+y
else
res=x-y
endif
return
end subroutine SUNDCALC

I do not use a DEF file. I then used the attached EXCEL file Book1.xls to test it. I Declare the DLL in a module thus

Option Explicit
Public Declare Sub SUNDCALC Lib "SUNDCALC.DLL" _
(ByRef x As Double, ByRef y As Double, ByRef i As Long, ByRef res As Double)

and add the Excel file to the Release or Debug folder that contains the DLL so that it can find it (otherwise add it to the c:windowssystem32 folder or somewhere in your default search path), whichever DLL you want to test.
The Visual basic code is

Private Sub CommandButton1_Click()
Dim x As Double
Dim y As Double
Dim i As Long
Dim res As Double

x = Range("var1").Value
y = Range("var2").Value
i = Range("flag").Value

Call SUNDCALC(x, y, i, res)

Range("result").Value = res

End Sub

Private Sub CommandButton2_Click()
Dim x As Double
Dim y As Double
Dim i As Long
Dim res As Double

x = Range("VAR3").Value
y = Range("VAR4").Value
i = Range("flag2").Value

Call SUNDCALC(x, y, i, res)

Range("res2").Value = res
End Sub
0 Kudos
ssund
Beginner
1,899 Views
Quoting - anthonyrichards
I use CVF 6.6C and it works OK for me. I just compile the following into a SUNDCALC.DLL :

subroutine SUNDCALC(x, y,i,res)
!DEC$ ATTRIBUTES DLLEXPORT, STDCALL, REFERENCE, ALIAS:"SUNDCALC" :: SUNDCALC
!DEC$ ATTRIBUTES REFERENCE :: x,y,i,res
real*8 x,y
integer i
real*8 res
if(i.eq.0)then
res=x+y
else
res=x-y
endif
return
end subroutine SUNDCALC

I do not use a DEF file. I then used the attached EXCEL file Book1.xls to test it. I Declare the DLL in a module thus

Option Explicit
Public Declare Sub SUNDCALC Lib "SUNDCALC.DLL" _
(ByRef x As Double, ByRef y As Double, ByRef i As Long, ByRef res As Double)

and add the Excel file to the Release or Debug folder that contains the DLL so that it can find it (otherwise add it to the c:windowssystem32 folder or somewhere in your default search path), whichever DLL you want to test.
The Visual basic code is

Private Sub CommandButton1_Click()
Dim x As Double
Dim y As Double
Dim i As Long
Dim res As Double

x = Range("var1").Value
y = Range("var2").Value
i = Range("flag").Value

Call SUNDCALC(x, y, i, res)

Range("result").Value = res

End Sub

Private Sub CommandButton2_Click()
Dim x As Double
Dim y As Double
Dim i As Long
Dim res As Double

x = Range("VAR3").Value
y = Range("VAR4").Value
i = Range("flag2").Value

Call SUNDCALC(x, y, i, res)

Range("res2").Value = res
End Sub

Thanks! It works like a charm in IVF 10.x I used the ifort /dl sundcalc.f90 /MT command and everything is fine.
I just needed a small example to have as a base for my real application.

Thanks again.
steve
0 Kudos
ssund
Beginner
1,899 Views
Quoting - ssund

Thanks! It works like a charm in IVF 10.x I used the ifort /dl sundcalc.f90 /MT command and everything is fine.
I just needed a small example to have as a base for my real application.

Thanks again.
steve

I have one more problem now. Most of my existing Fortran and the application I want to link with Excel is written in Fortran 77. I have tried to modify anthonyrichardsfortran to be Fortran 77 but I now I can not get the interface to work See below. My question is can I create the driver program i.e. SUNDCALC in f90 (sundcalc.f90) which then calls a subroutine written in Fortran 77?
When I compile this as ifort /dll sundcalc.for /MT it gives many errors (see attached)

cDEC$ NOFREEFORM
cDEC$ FIXEDFORMLINESIZE:72

subroutine SUNDCALC(x, y,i,res)
cDEC$ ATTRIBUTES DLLEXPORT, STDCALL, REFERENCE, ALIAS:'SUNDCALC' :: SUNDCALC
cDEC$ ATTRIBUTES REFERENCE :: x,y,i,res
real*8 x,y
integer i
real*8 res
call sundcalc2(x,y,i,res)
end
c
subroutine sundcalc2(xx,yy,ii,ress)
real*8 xx,yy,ress
integer ii
c
if(ii.eq.0)then
ress=xx+yy
else
ress=xx-yy
endif
c
return
end
0 Kudos
gib
New Contributor II
1,899 Views
Quoting - ssund

I have one more problem now. Most of my existing Fortran and the application I want to link with Excel is written in Fortran 77. I have tried to modify anthonyrichards fortran to be Fortran 77 but I now I can not get the interface to work See below. My question is can I create the driver program i.e. SUNDCALC in f90 (sundcalc.f90) which then calls a subroutine written in Fortran 77?
When I compile this as ifort /dll sundcalc.for /MT it gives many errors (see attached)

cDEC$ NOFREEFORM
cDEC$ FIXEDFORMLINESIZE:72

subroutine SUNDCALC(x, y,i,res)
cDEC$ ATTRIBUTES DLLEXPORT, STDCALL, REFERENCE, ALIAS:'SUNDCALC' :: SUNDCALC
cDEC$ ATTRIBUTES REFERENCE :: x,y,i,res
real*8 x,y
integer i
real*8 res
call sundcalc2(x,y,i,res)
end
c
subroutine sundcalc2(xx,yy,ii,ress)
real*8 xx,yy,ress
integer ii
c
if(ii.eq.0)then
ress=xx+yy
else
ress=xx-yy
endif
c
return
end
It seems that you are doing several unnecessary things, and some of them are wrong as well.

First, there isn't the distinction between Fortran77 and Fortran90 that you think. Fortran77 is contained within Fortran90, in the sense that a Fortran90 (or later) compiler like ifort will compile almost any Fortran77 program. So you really don't need to do anything to the code that Anthony supplied.

Second, why are you calling sundcalc2 from sundcalc, instead of just doing the calculation in sundcalc? You might think you have a F90 driver program calling a F77 subroutine, but actually all the code is F77 and also F90 (except for the following point). The file extension determines what assumptions the compiler makes, for all the code in the file.

Third, despite the unnecessariness, the code that you show compiles happily with the file name sundcalc.for. I think you actually named it sundcalc.f90 and tried to compile it with 'ifort sundcalc.f90 ...' This does indeed give errors, but if you change each 'cDEC$ ' to '!DEC$ ' to make it Fortran90 conforming, all is OK.

But, to repeat, this is all unnecessary. You can build a program with a mix of .for and .f90 files, although I'd recommend switching over fully to .f90, to get access to the powerful new features of Fortran90.
0 Kudos
Steven_L_Intel1
Employee
1,899 Views
I want to clarify something. The only difference between .for and .f90 is which source form the compiler assumes is being used. I agree that free-form source (.f90 file type) is preferable, but all Fortran 90/95/2003 "features" are available in fixed-form source.

The primary advantage of free-form source is that some classic Fortran coding errors can't be made in free-form source, such as characters dropped after column 72 and errors not diagnosed because blanks are not significant.
0 Kudos
anthonyrichards
New Contributor III
1,899 Views
I want to clarify something. The only difference between .for and .f90 is which source form the compiler assumes is being used. I agree that free-form source (.f90 file type) is preferable, but all Fortran 90/95/2003 "features" are available in fixed-form source.

The primary advantage of free-form source is that some classic Fortran coding errors can't be made in free-form source, such as characters dropped after column 72 and errors not diagnosed because blanks are not significant.

Yep, some of your lines are longer than 72 columns! Use Freeform!
0 Kudos
gib
New Contributor II
1,899 Views
I want to clarify something. The only difference between .for and .f90 is which source form the compiler assumes is being used. I agree that free-form source (.f90 file type) is preferable, but all Fortran 90/95/2003 "features" are available in fixed-form source.

The primary advantage of free-form source is that some classic Fortran coding errors can't be made in free-form source, such as characters dropped after column 72 and errors not diagnosed because blanks are not significant.
Yes, sorry that my statement was misleading. What I should have said was that I recommend starting to use the features of Fortran90. Separately I recommend using free-form source.
0 Kudos
ssund
Beginner
1,899 Views
Quoting - gib
Yes, sorry that my statement was misleading. What I should have said was that I recommend starting to use the features of Fortran90. Separately I recommend using free-form source.

Thanks to all for your comments but here is my situation.
I agree that f90 has some usefull extensions but Ihave quite a bit of legacy code that is in Fortran77 that works great as an executable. What I am trying to do isuse Excel 2003 as a front end to some of theseFortran programs and want to create a DLL to call Fortran. The problem I was seeing was that when I compiled the F77 (.for) it would give me errors on all the lines with c in column 1. All the legacy code has c in column 1 so I had to fix this.

I tried all your suggestions and I finally got it to compile and work as a DLL assundcalc.for (see below)
the compile line was ifort /dll sundcalc.for /MT
;

cDEC$ NOFREEFORM
cDEC$ FIXEDFORMLINESIZE:132
c234567
subroutine SUNDCALC(x, y,i,res)
c
cDEC$ ATTRIBUTES DLLEXPORT, STDCALL, REFERENCE, ALIAS:'SUNDCALC' :: SUNDCALC
cDEC$ ATTRIBUTES REFERENCE :: x,y,i,res
real*8 x,y
integer i
real*8 res
if(i.eq.0)then
res=x+y
else
ress=x-y
endif
c
return
end
c


Again thanks for all the help.

0 Kudos
Reply