replica nfl jerseysreplica nfl jerseyssoccer jerseyreplica nfl jerseys forums.silverfrost.com :: View topic - Matlab to FTN95
forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Matlab to FTN95

 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General
View previous topic :: View next topic  
Author Message
christyleomin



Joined: 08 Apr 2011
Posts: 155

PostPosted: Mon Dec 12, 2011 9:38 am    Post subject: Matlab to FTN95 Reply with quote

I have some Matlab routines which I would like to avoid rewriting in FORTRAN.

Is it possible to convert a Matlab routine to FORTRAN-FTN95?
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8210
Location: Salford, UK

PostPosted: Mon Dec 12, 2011 12:57 pm    Post subject: Reply with quote

Although one aways hesitates to say No, it seems to me to be very unlikely that anyone has even thought of trying to write a Mathlab to Fortran converter.

You can access a Fortran library from a Mathlab script but that is all.
Back to top
View user's profile Send private message AIM Address
christyleomin



Joined: 08 Apr 2011
Posts: 155

PostPosted: Mon Dec 12, 2011 9:03 pm    Post subject: Reply with quote

What about this? Is it good enough you think?

http://sourceforge.net/projects/matlab2fmex/

Christy
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 8210
Location: Salford, UK

PostPosted: Tue Dec 13, 2011 6:51 pm    Post subject: Reply with quote

Why not give it a try and see what it does?
Is a Fortran90 mex file anything like a standard Fortran source file?
Is it sufficiently versatile to convert your Mathlab code?
Back to top
View user's profile Send private message AIM Address
christyleomin



Joined: 08 Apr 2011
Posts: 155

PostPosted: Wed Dec 14, 2011 9:31 am    Post subject: Reply with quote

Thanks Paul.

Actually, I'm also in the porocess of developing new code which is finally intended for FTN95

But, in the initial stages I need to use some math libraies (equation solvers,etc) which I therefore start with Matlab because it has these inbuilt math functions.Finally,I will be codinmg my own math functions too.

So, enquired if I start with Matlab code would it be a quick one to convert to FTN95
Back to top
View user's profile Send private message
jjgermis



Joined: 21 Jun 2006
Posts: 404
Location: N�rnberg, Germany

PostPosted: Fri Jan 13, 2012 3:59 pm    Post subject: Reply with quote

We often use this strategy as well, i.e. test in Matlab and then write the final application in Fortran. However, since you do not have the code for some of the Matlab function you really have to start from scratch. Moreover if you have matrix opperations it is important to know that fortran is columnwise and Matlab row wise.

I have found the numerical recipes in fortran to be a good basis when developing your own libraries.
Back to top
View user's profile Send private message
christyleomin



Joined: 08 Apr 2011
Posts: 155

PostPosted: Sun Jan 15, 2012 8:51 am    Post subject: Reply with quote

jjgermis, thanks.

Sorry, but I do not follow when you say;

Quote:
Moreover if you have matrix opperations it is important to know that fortran is columnwise and Matlab row wise.


Can you please explain, what you mean by this?
Back to top
View user's profile Send private message
davidb



Joined: 17 Jul 2009
Posts: 560
Location: UK

PostPosted: Sun Jan 15, 2012 2:36 pm    Post subject: Reply with quote

What "routines" have you written in MATLAB? If you have just used high-level matrix functions, you can get the same functionality by using a library like LAPACK, EISPACK etc. Most of these Fortran libraries are the basis of MATLAB anyway (MATLAB is just an interface to Fortran libraries!).

If you're writing or translating low-level stuff, you need to think about how Fortran and MATLAB differ in the way they store 2D arrays in memory. Read up about Row-major order and Column-major order on Wikipedia.
_________________
Programmer in: Fortran 77/95/2003/2008, C, C++ (& OpenMP), java, Python, Perl
Back to top
View user's profile Send private message
christyleomin



Joined: 08 Apr 2011
Posts: 155

PostPosted: Mon Jan 16, 2012 1:55 am    Post subject: Reply with quote

Thanks davidb.

Yes, I did read wikepedia for row major order and column major order as suggested by davidb.

But, jjgermis, I see that both Fortran and MAtlab follow column major order

http://en.wikipedia.org/wiki/Row-major_order

Anyways, row major order or column major denote how the arrays are contiguously stored in memory.

How will it affect coding?

In the code I wil be dealing with aij and i always denoted the row and j the column.
Back to top
View user's profile Send private message
jjgermis



Joined: 21 Jun 2006
Posts: 404
Location: N�rnberg, Germany

PostPosted: Mon Jan 16, 2012 8:25 am    Post subject: Reply with quote

If you have a M 3x3 matrix the indices are always (row,column) to reference an entry.

When the matrix is saved in memory:

Matlab: M(1,1), M(1,2), M(1,3), M(2,1), M(2,2),... , M(3,2), M(3,3)
-> saving a row means you have to loop over the column indices

Fortran: M(1,1), M(2,1), M(3,1), M(1,2), M(2,2),..., M(2,3), M(3,3)
-> saving a column means you have to loop over the row indices

I you use the FTN95 debugger you can see how the matrix entries are saved.

With modern computers I cannot judge how much "time" you save by doing it correct for either languages. Moreover, if your application is not that complex you propably will not even notice anything. It is however, good practice to know how the language handles the data.
Back to top
View user's profile Send private message
brucebowler
Guest





PostPosted: Tue Jan 17, 2012 3:46 pm    Post subject: Re: Reply with quote

davidb wrote:
(MATLAB is just an interface to Fortran libraries!).


I don't think that's true anymore... matlab started that way, but it's grown and I don't think much of it is written in Fortran anymore...
Back to top
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> General All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group