View previous topic :: View next topic |
Author |
Message |
christyleomin
Joined: 08 Apr 2011 Posts: 155
|
Posted: Mon Dec 12, 2011 9:38 am Post subject: Matlab to FTN95 |
|
|
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 |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8210 Location: Salford, UK
|
Posted: Mon Dec 12, 2011 12:57 pm Post subject: |
|
|
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 |
|
 |
christyleomin
Joined: 08 Apr 2011 Posts: 155
|
|
Back to top |
|
 |
PaulLaidler Site Admin
Joined: 21 Feb 2005 Posts: 8210 Location: Salford, UK
|
Posted: Tue Dec 13, 2011 6:51 pm Post subject: |
|
|
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 |
|
 |
christyleomin
Joined: 08 Apr 2011 Posts: 155
|
Posted: Wed Dec 14, 2011 9:31 am Post subject: |
|
|
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 |
|
 |
jjgermis
Joined: 21 Jun 2006 Posts: 404 Location: N�rnberg, Germany
|
Posted: Fri Jan 13, 2012 3:59 pm Post subject: |
|
|
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 |
|
 |
christyleomin
Joined: 08 Apr 2011 Posts: 155
|
Posted: Sun Jan 15, 2012 8:51 am Post subject: |
|
|
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 |
|
 |
davidb
Joined: 17 Jul 2009 Posts: 560 Location: UK
|
Posted: Sun Jan 15, 2012 2:36 pm Post subject: |
|
|
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 |
|
 |
christyleomin
Joined: 08 Apr 2011 Posts: 155
|
Posted: Mon Jan 16, 2012 1:55 am Post subject: |
|
|
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 |
|
 |
jjgermis
Joined: 21 Jun 2006 Posts: 404 Location: N�rnberg, Germany
|
Posted: Mon Jan 16, 2012 8:25 am Post subject: |
|
|
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 |
|
 |
brucebowler Guest
|
Posted: Tue Jan 17, 2012 3:46 pm Post subject: Re: |
|
|
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 |
|
 |
|