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

FORTRAN 77 F2C

heysiattalab__saeed
1,176 Views

Hello all. I have some FORTRAN 77 code that I am trying to convert it to C/C++ using F2C. I can compile my FORTRAN source code using IVF but when I am trying to convert it to C using F2C I get the following error :

Error on line 5 of TAGLINE.INS: unclassifiable statement (starts "structure/")
Error on line 33 of TAGLINE.INS: unclassifiable statement (starts "record/sta")

TAGLINE.INS is NOT my source file. It is an include file that I include it in my source code and F2C complains about include file. Here is my include file (TAGLINE.INS) :

 

C
C
C***  SCRATCH INPUT DATA FROM FILE FNAM  (.RTV = RAW INPUT TAG VALUE)
C
          STRUCTURE  /STAGRICL/

            CHARACTER*76     UFN     !! U72 FILENAME.UP.CASE     INIT BLANK
            CHARACTER*76     RFN      ! R72 FILENAME.RAWCASE     INIT BLANK
            INTEGER*4        LFN      ! I4  FILENAME.LENGTH      INIT 0    

            CHARACTER*32     USN     !! U32 SECTION-NAME-UP.CASE INIT BLANK
            CHARACTER*32     RSN      ! R32 SECTION-NAME RAWCASE INIT BLANK
            INTEGER*4        LSN      ! I4  SECTION-NAME-LENGTH  INIT 0    

            CHARACTER*32     UTN     !! U32 TAG-NAME-UP.CASE     INIT BLANK
            CHARACTER*32     RTN      ! R32 TAG-NAME-RAWCASE     INIT BLANK
            INTEGER*4        LTN      ! I4  TAG-NAME-LENGTH      INIT 0    

            CHARACTER*80     UTV      ! U80 TAG-VALUE.UP.CASE.IN INIT BLANK
            CHARACTER*80     RTV     !! R80 TAG-VALUE.RAWCASE.IN INIT BLANK
            INTEGER*4        LTV      ! I4  TAG-VALUE-LENGTH     INIT 0    

            CHARACTER*80     RWL      ! R80 TAG-RAW.WHOLE.LINE   INIT BLANK
            INTEGER*4        LWL      ! I4  TAG-RAW.WHOLE.LENGTH INIT 0    
            INTEGER*4        NWL      ! I4  LIN.#.IN.ORIG.FILE   INIT 0    

            LOGICAL*4        SET      ! L4  TAGRICL   SET YET ?  INIT FALSE
            LOGICAL*4        USE      ! L4  TAGRICL  USED YET ?  INIT FALSE

          END STRUCTURE
C
C
      PARAMETER                   (N1000=200)
      RECORD /STAGRICL/   TAGRICL (N1000)  ! 1000.MAX TAG.NAMES.PER.FILE

 

Obviously, F2C complains about structure STAGRICL in TAGLINE.INS.

Thank you so much for your help and guidance. 

 

0 Kudos
9 Replies
Steve_Lionel
Honored Contributor III
1,175 Views

This forum is not related to F2C, which is something I can't recommend that ANYONE use in 2020. Even when F2C was reasonable to use, it wasn't intended as a tool for conversion but rather as a way to compile FORTRAN code if you had a C compiler but not Fortran. 

I will comment that this code is NOT FORTRAN 77. STRUCTURE, RECORD, INCLUDE, INTEGER*4 are all extensions to F77. STRUCTURE/RECORD, in particular, was a DEC extension that was not commonly implemented in F2C's time.

That said, if you know anything about C, and if you don't you're doomed to failure here, it is straightforward to reinterpret this as a C struct.

0 Kudos
heysiattalab__saeed
1,175 Views

Hi Steve, 

Thank you for your reply. What tool would you recommend for converting a HUGE FORTRAN code to C ? The code is years of development and I can not really rewrite in C, as it would take a lot of time. 

Thanks. 

0 Kudos
JohnNichols
Valued Contributor III
1,173 Views

heysiattalab, saeed wrote:

Hi Steve, 

Thank you for your reply. What tool would you recommend for converting a HUGE FORTRAN code to C ? The code is years of development and I can not really rewrite in C, as it would take a lot of time. 

Thanks. 

Put Fortran in  DLL and then use a C calling program  -- 

 

0 Kudos
mecej4
Honored Contributor III
1,175 Views

Before you can use f2c, you would need to convert your source code to standard Fortran 77, or the dialect of it that f2c understands.

 

Take note of this statement from page 2, para 1 of the f2c documentation at http://www.netlib.org/f2c/f2c.pdf :

Thus the C output of f2c would probably be something of a nightmare to maintain as C; it would be much more sensible to maintain the original Fortran, translating it anew each time it changed.

Do not undertake translation of a large body of code without careful planning and assessment.You may well spend several months, only to reach a point where you find out that the task is impossible or not worthwhile. 

0 Kudos
JohnNichols
Valued Contributor III
1,173 Views

What meccej4 is saying in very polite language is == this is a really bad idea and one should take it after climbing Mt Everest and considering it would be harder than that. 

0 Kudos
Barbara_P_Intel
Moderator
1,175 Views

I've heard anecdotes complaining about performance from developers who ported applications from Fortran to C.  They have to work hard to get C to match the runtime performance of the Fortran code.

 

0 Kudos
Steve_Lionel
Honored Contributor III
1,175 Views

I always recommend against converting a working program from one language to another. It usually ends badly. You are certain to introduce bugs or other unwanted behavior. Certainly if one was to do this, an ancient translator such as F2C is the worst possible approach.

Why do you want to do this? What do you think it will accomplish? It certainly won't make the code any more maintainable.

0 Kudos
heysiattalab__saeed
1,175 Views

This code is running a piece of hardware and porting FORTRAN to C is a part of renovation project for software along the hardware which is very old. I am not a big fan of code conversion myself but it has been assigned to me. I am concerned with run time errors, performance, and bad behavior after conversion and it might be also impossible after a few months of work. 

0 Kudos
Steve_Lionel
Honored Contributor III
1,175 Views

What is the purpose of the language conversion? Why can't the code stay in Fortran?

0 Kudos
Reply