4.08333

4.1 | 12 ratings Rate this file 314 downloads (last 30 days) File Size: 1.34 MB File ID: #5260

f2matlab

by Ben Barrowes

 

16 Jun 2004 (Updated 01 May 2009)

Code covered by BSD License  

Converts basic fortran90 source code to MATLAB source code.

Download Now | Watch this File

File Information
Description

4. F2MATLAB CAPABILITIES: f2matlab is aimed at converting numerical Fortran90 code to Matlab m-files. Accordingly, only basic data types and constructions are recommended. f2matlab can handle: all numeric types (handled by Matlab interpreter) most string functions comparisons, branches, loops, types, etc. basic read/write/print statements (if it's not too fancy...) 5. F2MATLAB LIMITATIONS: f2matlab can not handle some features of fortran90 yet. These include: can't handle difficult IO and read and write statements, goto (of course), equivalence, and pointers.

Acknowledgements
This submission has inspired the following:
GaussHermite
MATLAB release MATLAB 7 (R14)
Zip File Content  
Other Files
f2matlab/addGetArg.m,
f2matlab/addreadf.m,
f2matlab/addVars.m,
f2matlab/addwritef.m,
f2matlab/aftercomment.m,
f2matlab/assignSwitches.m,
f2matlab/breakOffFirstFormat.m,
f2matlab/buildTypeDefLine.m,
f2matlab/caseProtectedML.m,
f2matlab/changelog,
f2matlab/changeoperator_f.m,
f2matlab/comp_spec_func/intfaces.f90,
f2matlab/comp_spec_func/mairya.f90,
f2matlab/comp_spec_func/mairyb.f90,
f2matlab/comp_spec_func/mairyzo.f90,
f2matlab/comp_spec_func/maswfa.f90,
f2matlab/comp_spec_func/maswfb.f90,
f2matlab/comp_spec_func/mbernoa.f90,
f2matlab/comp_spec_func/mbernob.f90,
f2matlab/comp_spec_func/mbeta.f90,
f2matlab/comp_spec_func/mcchg.f90,
f2matlab/comp_spec_func/mcerror.f90,
f2matlab/comp_spec_func/mcerzo.f90,
f2matlab/comp_spec_func/mcgama.f90,
f2matlab/comp_spec_func/mch12n.f90,
f2matlab/comp_spec_func/mchgm.f90,
f2matlab/comp_spec_func/mchgu.f90,
f2matlab/comp_spec_func/mcik01.f90,
f2matlab/comp_spec_func/mciklv.f90,
f2matlab/comp_spec_func/mcikna.f90,
f2matlab/comp_spec_func/mciknb.f90,
f2matlab/comp_spec_func/mcikva.f90,
f2matlab/comp_spec_func/mcikvb.f90,
f2matlab/comp_spec_func/mcisia.f90,
f2matlab/comp_spec_func/mcisib.f90,
f2matlab/comp_spec_func/mcjk.f90,
f2matlab/comp_spec_func/mcjy01.f90,
f2matlab/comp_spec_func/mcjylv.f90,
f2matlab/comp_spec_func/mcjyna.f90,
f2matlab/comp_spec_func/mcjynb.f90,
f2matlab/comp_spec_func/mcjyva.f90,
f2matlab/comp_spec_func/mcjyvb.f90,
f2matlab/comp_spec_func/mclpmn.f90,
f2matlab/comp_spec_func/mclpn.f90,
f2matlab/comp_spec_func/mclqmn.f90,
f2matlab/comp_spec_func/mclqn.f90,
f2matlab/comp_spec_func/mcomelp.f90,
f2matlab/comp_spec_func/mcpbdn.f90,
f2matlab/comp_spec_func/mcpsi.f90,
f2matlab/comp_spec_func/mcsphik.f90,
f2matlab/comp_spec_func/mcsphjy.f90,
f2matlab/comp_spec_func/mcva1.f90,
f2matlab/comp_spec_func/mcva2.f90,
f2matlab/comp_spec_func/mcyzo.f90,
f2matlab/comp_spec_func/me1xa.f90,
f2matlab/comp_spec_func/me1xb.f90,
f2matlab/comp_spec_func/me1z.f90,
f2matlab/comp_spec_func/meix.f90,
f2matlab/comp_spec_func/melit.f90,
f2matlab/comp_spec_func/melit3.f90,
f2matlab/comp_spec_func/menxa.f90,
f2matlab/comp_spec_func/menxb.f90,
f2matlab/comp_spec_func/merror.f90,
f2matlab/comp_spec_func/meulera.f90,
f2matlab/comp_spec_func/meulerb.f90,
f2matlab/comp_spec_func/mfcoef.f90,
f2matlab/comp_spec_func/mfcs.f90,
f2matlab/comp_spec_func/mfcszo.f90,
f2matlab/comp_spec_func/mffk.f90,
f2matlab/comp_spec_func/mgamma.f90,
f2matlab/comp_spec_func/mherzo.f90,
f2matlab/comp_spec_func/mhygfx.f90,
f2matlab/comp_spec_func/mhygfz.f90,
f2matlab/comp_spec_func/mik01a.f90,
f2matlab/comp_spec_func/mik01b.f90,
f2matlab/comp_spec_func/mikna.f90,
f2matlab/comp_spec_func/miknb.f90,
f2matlab/comp_spec_func/mikv.f90,
f2matlab/comp_spec_func/mincob.f90,
f2matlab/comp_spec_func/mincog.f90,
f2matlab/comp_spec_func/mitairy.f90,
f2matlab/comp_spec_func/mitika.f90,
f2matlab/comp_spec_func/mitikb.f90,
f2matlab/comp_spec_func/mitjya.f90,
f2matlab/comp_spec_func/mitjyb.f90,
f2matlab/comp_spec_func/mitsh0.f90,
f2matlab/comp_spec_func/mitsl0.f90,
f2matlab/comp_spec_func/mitth0.f90,
f2matlab/comp_spec_func/mittika.f90,
f2matlab/comp_spec_func/mittikb.f90,
f2matlab/comp_spec_func/mittjya.f90,
f2matlab/comp_spec_func/mittjyb.f90,
f2matlab/comp_spec_func/mjdzo.f90,
f2matlab/comp_spec_func/mjelp.f90,
f2matlab/comp_spec_func/mjy01a.f90,
f2matlab/comp_spec_func/mjy01b.f90,
f2matlab/comp_spec_func/mjyna.f90,
f2matlab/comp_spec_func/mjynb.f90,
f2matlab/comp_spec_func/mjyv.f90,
f2matlab/comp_spec_func/mjyzo.f90,
f2matlab/comp_spec_func/mklvna.f90,
f2matlab/comp_spec_func/mklvnb.f90,
f2matlab/comp_spec_func/mklvnzo.f90,
f2matlab/comp_spec_func/mlagzo.f90,
f2matlab/comp_spec_func/mlamn.f90,
f2matlab/comp_spec_func/mlamv.f90,
f2matlab/comp_spec_func/mlegzo.f90,
f2matlab/comp_spec_func/mlgama.f90,
f2matlab/comp_spec_func/mlpmn.f90,
f2matlab/comp_spec_func/mlpmns.f90,
f2matlab/comp_spec_func/mlpmv.f90,
f2matlab/comp_spec_func/mlpn.f90,
f2matlab/comp_spec_func/mlpni.f90,
f2matlab/comp_spec_func/mlqmn.f90,
f2matlab/comp_spec_func/mlqmns.f90,
f2matlab/comp_spec_func/mlqna.f90,
f2matlab/comp_spec_func/mlqnb.f90,
f2matlab/comp_spec_func/mmtu0.f90,
f2matlab/comp_spec_func/mmtu12.f90,
f2matlab/comp_spec_func/mothpl.f90,
f2matlab/comp_spec_func/mpbdv.f90,
f2matlab/comp_spec_func/mpbvv.f90,
f2matlab/comp_spec_func/mpbwa.f90,
f2matlab/comp_spec_func/mpsi.f90,
f2matlab/comp_spec_func/mrctj.f90,
f2matlab/comp_spec_func/mrcty.f90,
f2matlab/comp_spec_func/mrswfo.f90,
f2matlab/comp_spec_func/mrswfp.f90,
f2matlab/comp_spec_func/mscka.f90,
f2matlab/comp_spec_func/msckb.f90,
f2matlab/comp_spec_func/msdmn.f90,
f2matlab/comp_spec_func/msegv.f90,
f2matlab/comp_spec_func/msphi.f90,
f2matlab/comp_spec_func/msphj.f90,
f2matlab/comp_spec_func/msphk.f90,
f2matlab/comp_spec_func/msphy.f90,
f2matlab/comp_spec_func/mstvh0.f90,
f2matlab/comp_spec_func/mstvh1.f90,
f2matlab/comp_spec_func/mstvhv.f90,
f2matlab/comp_spec_func/mstvl0.f90,
f2matlab/comp_spec_func/mstvl1.f90,
f2matlab/comp_spec_func/mstvlv.f90,
f2matlab/comp_spec_func/TESTING_csf.m,
f2matlab/convertWrite.m,
f2matlab/dispback.m,
f2matlab/empt0.m,
f2matlab/examples/as245.f90,
f2matlab/examples/as245.m,
f2matlab/examples/BayesWi_test.f90,
f2matlab/examples/BayesWi_test.m,
f2matlab/examples/dgauleg.f,
f2matlab/examples/dgauleg.f90,
f2matlab/examples/dgauleg.m,
f2matlab/examples/f2ml_tempfile,
f2matlab/examples/femprb,
f2matlab/examples/femprb.f90,
f2matlab/examples/femprb.m,
f2matlab/examples/H1f.f,
f2matlab/examples/H1f.f90,
f2matlab/examples/H1f.m,
f2matlab/examples/lpmns.f,
f2matlab/examples/lpmns.f90,
f2matlab/examples/lpmns.m,
f2matlab/examples/lpmns2.f,
f2matlab/examples/lpmns2.m,
f2matlab/examples/lpmns2.mat,
f2matlab/examples/lqmns.f,
f2matlab/examples/lqmns.f90,
f2matlab/examples/lqmns.m,
f2matlab/examples/mcpbdn.f90,
f2matlab/examples/mcpbdn.for,
f2matlab/examples/mcpbdn.m,
f2matlab/examples/quadrule_prb,
f2matlab/examples/quadrule_prb.f90,
f2matlab/examples/quadrule_prb.m,
f2matlab/examples/slatec_test2.f90,
f2matlab/examples/slatec_test2.m,
f2matlab/examples/stroud_prb,
f2matlab/examples/stroud_prb.f90,
f2matlab/examples/stroud_prb.m,
f2matlab/examples/TESTING_ex.m,
f2matlab/examples/toms757_prb,
f2matlab/examples/toms757_prb.f90,
f2matlab/examples/toms757_prb.m,
f2matlab/examples/zztest,
f2matlab/examples/zztest.f90,
f2matlab/examples/zztest.m,
f2matlab/f2matlab.m,
f2matlab/f2matlab_3.0.m,
f2matlab/f2mWarning.m,
f2matlab/findend_f.m,
f2matlab/findendSub_f.m,
f2matlab/findlefts_f.m,
f2matlab/findNext.m,
f2matlab/findNextWord.m,
f2matlab/findrights_f.m,
f2matlab/fix_concats.m,
f2matlab/fixDataGroups.m,
f2matlab/fixEndType.m,
f2matlab/fixLabeledDoLoops.m,
f2matlab/fixMultiStatementLines.m,
f2matlab/fixNotOperator.m,
f2matlab/fixScalarCalls.m,
f2matlab/getarg.m,
f2matlab/getCaseProtectedML.m,
f2matlab/getExtraFunctions.m,
f2matlab/getfunwordsonly.m,
f2matlab/getfunwordsonlyML.m,
f2matlab/getLocalVarType.m,
f2matlab/getTopGroupsAfterLoc.m,
f2matlab/getTopLevelStrings.m,
f2matlab/getVarSpecs.m,
f2matlab/hassubscript_f.m,
f2matlab/HINTS,
f2matlab/implicitParse.m,
f2matlab/implicitRules.m,
f2matlab/inaDQstring_f.m,
f2matlab/inastring2_f.m,
f2matlab/inastring_f.m,
f2matlab/inbracket2.m,
f2matlab/inbracket_f.m,
f2matlab/incomment.m,
f2matlab/insertLocalVar.m,
f2matlab/INSTALL,
f2matlab/insubscript_f.m,
f2matlab/inwhichlast_f.m,
f2matlab/iscomplexf.m,
f2matlab/isInteger.m,
f2matlab/iskeep_f.m,
f2matlab/isnameletter.m,
f2matlab/isnumber.m,
f2matlab/keepSomeCases.m,
f2matlab/lastNonSpace.m,
f2matlab/maxloc.m,
f2matlab/module_adj.m,
f2matlab/nextNonSpace.m,
f2matlab/output_acceptable.m,
f2matlab/protectSomeStrings.m,
f2matlab/readf.m,
f2matlab/README,
f2matlab/remLocalVar.m,
f2matlab/replaceword_f.m,
f2matlab/setUpLocalVar.m,
f2matlab/showall_f.m,
f2matlab/strrel.m,
f2matlab/takeCareOfIncludeFiles.m,
f2matlab/takeCareOfIncludeFiles2.m,
f2matlab/takeCareOfTypes.m,
f2matlab/updatefunstr2_f.m,
f2matlab/updatefunstr_1line_f.m,
f2matlab/updatefunstr_f.m,
f2matlab/validSpot.m,
f2matlab/varInUsedMods.m,
f2matlab/varType.m,
f2matlab/w.m,
f2matlab/wordconverter_f.m,
f2matlab/writef.m,
f2matlab/zeroVarDec.m,
f2matlab/ztest.m,
f2matlab/ztest1.m,
f2matlab/zz_clean.m,
f2matlab/zz_convert.m,
f2matlab/zztest.m
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (13)
07 Mar 2006 shahab ghomi  
29 Mar 2006 peter spellucci  
25 Apr 2006 Malin Premaratne

This is a very useful function

23 Jun 2006 Anthony Kendall

Though it's not perfect (because of the ambiguity of the GOTO, READ, and WRITE functions in FORTRAN, they don't convert correctly), this converted about 1000 lines of code for me that I was then able to debug and convert to MATLAB format in about 8 hours. Not bad, considering the code was written by someone else!

08 Nov 2006 Thomas Clark

The actual utility is really useful... When it works.
However, (I think due to the ambiguity between row and column vectors in Fortran) I found a lot of problems in translation, where it just ground to a halt.

In a sense that's to be expected; but there is almost no error handling to cope with that kind of situation- If I could just find out which line of the source code was causing the trouble, I'd be able to comment that section out in the F90 file and manually translate those particular lines. As the f2matlab code is largely uncommented it's havoc to try and trace which lines of code cause the translation problem.

Don't get me wrong; this can be extremely useful code - and clearly a lot of effort has gone into it's development. However, it needs to be a bit more transparent to help us get over the patches where the ambiguity of Fortran lets the translation down.

12 Nov 2006 aws ataallah  
05 Dec 2006 rakesh reddy govindapur

good work

28 Dec 2007 thangjam singh

very good

18 Mar 2008 Fat Hidalgo

I tried to run the code but I keep getting the error:

??? Input argument "filename" is undefined.

Error in ==> f2matlab at 101
 if exist(filename,'file')==2

I think this is because Matlab does not like when functions are defined in the script. I should define the function outside of the script in a separate .m file, but when I try to do so, I just get more errors. It's hard for to to see what I need to cut from the original program to define the function separately. Anybody with comments on this please email me.

08 Apr 2008 anonymous anonymous

Hello
I have tried to convert the where statement applied to a 2D array to matlab and it seems f2matlab does not translate well.
Best Regards
Eduardo

program ed_example
   integer B(10, 2)

   B(1:10, 1) = 0
   B(1:10, 2) = 1
   where (B(:,:)>0)
      B(:,:) = B(:,:) + 9
   endwhere
end program

 Translating:
f2matlab('ed_example.f')

ans =
b([1:10], 1) = 0;
b([1:10], 2) = 1;
fmask=(b(:,:)>0);
b(fmask,:) = b(fmask,:) + 9;
endwhere;

Running:
>> b(fmask,:) = b(fmask,:) + 9
??? Index exceeds matrix dimensions.

19 Apr 2009 Qun HAN

It's great to know this great tool is still imporved.

02 Nov 2009 Martin Richard

Very useful package indeed. Thank you.

19 Nov 2009 Hastiepen

I know nothing about Fortran, and had to convert some code into Matlab. The conversions that f2matlab made helped me immensely to give me a starting point. Many thanks!

Please login to add a comment or rating.
Updates

Added module support.

16 Nov 2004

Enhancements, bug fixes.

30 Nov 2004

Enhancements, bug fixes.

09 Dec 2004

Enhancements, bug fixes.
Also added support for simple IO -- read/write/print statments inclusing formatting.

15 Dec 2004

Enhancements, bug fixes.
Added support for implied do loops.

24 Jan 2005

Some bug fixes.

09 Feb 2005

bug fixes, more robust

01 Mar 2005

01/20/05 - some bug fixes
02/08/05 - added try catch's
02/24/05 - added some support for fortran string comparisons, date_and_time
02/25/05 - added some support for functions as arguments

15 Mar 2005

More bug fixes. Support for strings as cells. I/O enhancements.

15 Mar 2005

Many bugs is last dist.

22 Mar 2005

03/09/05 - put fix() around declared integers
03/14/05 - some fixes, loop var now correct on exit from loop
03/21/05 - rewrote some parts to deal with var decs better
save (or declared with a value) vars in fortran are now persistent

30 Mar 2005

Bug fixes.

12 Dec 2005

Some bug fixes. Some enhancements.

14 Dec 2005

Some improvements and fixes.

16 May 2006

Fixed some bugs.
Added matlab reserve word variables changes.

06 Jun 2006

Changed description

31 Aug 2006

Speed improvement.

Bug fixes.

Module capability better.

06 Apr 2007

Bugfixes, added functionality.

16 Oct 2007

updated description

27 Dec 2007

Many bug fixes and major upgrade of capabilities.

05 Nov 2008

Some documentation updates and bug fixes.

04 Feb 2009

bug fixes, features added, more robust

01 May 2009

Several bug fixes and enhancements. Include files, types, etc.

Tag Activity for this File
Tag Applied By Date/Time
external interface Ben Barrowes 22 Oct 2008 07:24:01
fortran Ben Barrowes 22 Oct 2008 07:24:01
matlab Ben Barrowes 22 Oct 2008 07:24:01
convert Ben Barrowes 22 Oct 2008 07:24:01
utilities Ben Barrowes 22 Oct 2008 07:24:01
translate Ben Barrowes 22 Oct 2008 07:24:01
port Ben Barrowes 04 Feb 2009 15:34:08
convert Witali 13 Feb 2009 10:45:51
external interface Witali 13 Feb 2009 10:45:56
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com