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 7050057
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:05:49+00:00 2026-05-28T03:05:49+00:00

I am using python as an interface to several fortran files in my model.

  • 0

I am using python as an interface to several fortran files in my model. I want to duplicate a fortran file several times but at each copy, I will change the parameters that describe my model.

For example: I have the fortran file below

!file.f
! This is a fortran code

!Parameters
alpha = 0.5
beta = 100
...

I want to copy file.f several times such that I will have file1.f, file2.f, file3.f, etc. However, at each file duplicated I want to change the parameters alpha and beta automatically. Thanks

EDIT: Let me explain a little further. I am using python to implement data assimilation (kalman filtering) to models that have already been developed in fortran. Basically, how it works is at each specified time step the fortran models stop running, then I integrate real world data to model data and I do this in python. Then after the integration (assimilation), I rerun the same models however this time using new parameters that I obtained from fusing data from model and observations and the new initial conditions. I use python to do everything except run the model which is being done by fortran.

  • 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-28T03:05:50+00:00Added an answer on May 28, 2026 at 3:05 am

    I think the most consistent way to go would be to use a templating engine. Python has a lot of then, usually deployed within web applications.

    But the purpose of templating engines is exactly to allow one to have the bulk of the code, that needs nos change as static text, and through some special markup interpolate that with variables generated within the Python code.

    Depending on the complexity of your parameters you could even don’t need any separte templating engine at all, and just go on with Python string formating capabilities, as in the example bellow.

    Template engines could provide you with a bit extra capacity, as the ability to unroll loops and conditionals inside the template.

    Example – write your fortram template something like:

    !file.f
    ! This is a fortran code
    
    !Parameters
    alpha = %(alpha)s
    beta = %(beta)s
    

    And in the Python code, write something like:

    template = open("fortram_template.for", "rt").read()
    data = {"alpha": 0.5, "beta": 100}
    
    with open("fortram_1.for", "wt") as output:
        output.write (template % data)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Python's Imaging Library I want to create a PNG file. I would like
I'm using Python and I want to do a drag & drop interface. For
I am using Python 3.1.1 on Mac OS X 10.6.2 and need an interface
Using Python I want to be able to draw text at different angles using
Using Python, how would I go about reading in (be from a string, file
Using Python, I want to know whether Java is installed.
Using Python, how does one parse/access files with Linux-specific features, like ~/.mozilla/firefox/*.default ? I've
I have written a python package which consists of several .py files which contain
I have some code to interface Python to C++ which works fine but every
I need to interface a C console program (as subprocess) with Python using stdin/stdout.

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.