Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Object oriented\\ Excel

BABAK
Beginner
544 Views
Hi

   I have two questions about ifort:

1. Does modern Fortran(2003-2008) supports all the requirements of object oriented programming compared to C++ ? If not,what are those capabilities and what is their usage?

2. Is it possible to open an excel file in fortran and manipulate the data in different sheets of the file and then save and close it?If so,how?

Thanks
0 Kudos
5 Replies
Steven_L_Intel1
Employee
544 Views
I am not sure how one answers your first question.  What are these "requirements"?  Fortran's OO support does not match C++ feature-for-feature.  For example, while it has destructors (finalizers) it does not have constructors (though you can fake it with your own generic declaration.)  Fortran was careful to adopt the most useful part of OO without going down the rabbit hole that C++ did.

As for your second question, yes, it is possible.  There is an example provided with the product in the COM zip file, and I have seen users contribute code here in the forum.
0 Kudos
BABAK
Beginner
544 Views
Hi again:

I meant does fortran has all the capabilities to write a code completely in OOP and doesn't lack any necessary feature?
0 Kudos
Steven_L_Intel1
Employee
544 Views
It depends on your definition of OOP and "necessary".  Fortran certainly has the major aspects of OOP: extensibility, polymorphism and type-bound procedures.  You tell me what you think is necessary and I can tell you if Fortran has it.  Nobody is claiming that Fortran has every OOP feature ever conceived.
0 Kudos
anthonyrichards
New Contributor III
544 Views
Question 1 I shall leave to Steve.
Question 2 appears to  not linked to question 1, and leads me to ask what is the driving force behind it?
Excel clearly can use Visual basic (which is pefectly adapted for OOP) to control Windows objects as well as run non-VBS code from DLL's - which may be derived from Fortran code having the correct calling convention - via the Declare statement. Why not just learn some VBA which can open Excel and all sorts of other objects? I don't think that we Fortran programmers are so hidebound to think every thing needs to be done in Fortran if there is an easier way in another language whose basics are relatively easy to learn.
0 Kudos
Arjen_Markus
Honored Contributor I
544 Views
IMHO Fortran 2003 has enough capabilities to create object-oriented programs. It may not be the style
of OOP that is encouraged by C++, for instance Fortran 2003 has no multiple inheritance, but every OO
language that I know of has its own style of OOP. Fortran does not emphasize the role of classes in the same
way as C++ for instance.

It can even do things that are not as easy or as transparent in C++. For instance: procedure pointers and
type-bound procedures use the very same syntax. That means that it is irrelevant to the using code how
the procedure is bound to the object. A simple example: "age"-dependent behaviour of an object
representing some animal:

type :: animal
    ...
    procedure(behave_in_some_way) :: behave
contains
    ...
end type

if ( this%age > 2.0 ) then ! Animal becomes mature after 2 years
    this%behave => behave_as_adult
endif

The procedure "this%behave" can be changed dynamically per object. (I have adapted this from
my book "Modern Fortran in Practice")

I am not claiming that it is always easy to use an object-oriented programming style in Fortran,
but it definitely is possible and practical. Even before Fortran 2003, you could achieve nice results.

Regards,

Arjen
0 Kudos
Reply