Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6765543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:43:27+00:00 2026-05-26T14:43:27+00:00

I have some Fortran 77 source files that I’m trying to convert from a

  • 0

I have some Fortran 77 source files that I’m trying to convert from a non-standard STRUCTURE and RECORD syntax to the standardized Fortran 90 TYPE syntax. One tricky aspect of this is the different way that structure members are addressed.

Non-standard:

s.member = 1

Standard:

s%member = 1

So, I need to trap all uses of periods in these sort of scenarios and replace them with % characters. Not too bad, except when you think about all of the ways that periods can be used (decimal points in numbers, filenames in include statements, punctuation in comments, Fortran 77 relational operators, maybe others). I’ve done some preprocessing to fix the relational operators to use the Fortran 90 symbols, and I don’t really care about mangling the grammar of comments, but I haven’t come up with a good approach to translate the . to % for the cases above. It seems like I should be able to do this with sed, but I’m not sure how to match the instances I need to fix. Here are the rules that I’ve thought of:

On a line-by-line basis:

  • If the line begins with <whitespace>include, then we shouldn’t do anything to that line; pass it through to the output, so we don’t mess up the filename inside the include statement.

  • The following strings are operators that don’t have symbolic equivalents, so they must be left alone: .not. .and. .or. .eqv. .neqv.

  • Otherwise, if we find a period that is surrounded by 2 non-numeric characters (so it’s not a decimal point), then it should be the operator that I’m looking to replace. Change that period to a %.

I’m not a native Fortran speaker myself, so here are some examples:

include 'file.inc'        ! We don't want to do anything here. The line can
                          ! begin with some amount of whitespace

if x == 1 .or. y > 2.0    ! In this case, we don't want to touch the periods that
                          ! are part of the logical operator ".or.". We also don't
                          ! want to touch the period that is the decimal point 
                          ! in "2.0".
if a.member < 4.0 .and. b.othermember == 1.0 ! We don't want to touch the periods
                                             ! inside the numbers, but we need to
                                             ! change the "a." and "b." to "a%"
                                             ! and "b%".

Any good way of tackling this problem?

Edit: I actually found some additional operators that contain a dot in them that don’t have symbolic equivalents. I’ve updated the rule list above.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T14:43:27+00:00Added an answer on May 26, 2026 at 2:43 pm

    You can’t do this with a regexp, and it’s not that easy.

    If I had to do what you have to, I would probably do it by hand, unless the codebase is huge. If the former applies, first replace all [a-zA-Z0-9].[a-zA-Z] to something very weird that is guaranteed never to compile, something like “@WHATEVER@”, then proceed to search all these entries and replace them by hand after manual control.

    If the amount of code is huge, then you need to write a parser. I would suggest you to use python to tokenize basic fortran constructs, but remember that fortran is not an easy language to parse. Work “per routine”, and try to find all variable names used, using them as a filter. If you encounter something like a.whatever, and you know that a is in the list of local or global vars, apply the change.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying to strip out some data from HTML files. I have
I have to convert some code from Fortran so doesn't know how what this
I have some old fortran 77 I'm trying to port to gcc on Windows.
I have a FORTRAN 95 program that needs to make some calls to the
I have a fortran program generating unformatted files and I am trying to read
I have an application that we're trying to migrate to 64bit from 32bit. It's
I have some routines written in fortran that I'd like to use in my
I have been trying to call some functions from a library provided by a
I'm trying to figure out how to redirect output from some FORTRAN code for
I have a line of Fortran code, which includes some text. I'm changing the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.