Git Product home page Git Product logo

nml-to-f90's People

Contributors

perrette avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

nml-to-f90's Issues

add topic

I suggest adding the topics namelist, fortran

Clean things up

The code has evolved from making a read/write namelist code from the namelist itself to a more complete fortran code parser that generate both the namelist and the I/O routines. I noticed that the really useful bit was to code parsing with 1) namelist generation and 2) I/O routines. It would make sense to refactorize the code a bit to make these steps more natural.

Old way

To illustrate that, here is an example of the current commands I use in a research code.

  • create namelist params_default.nml from source code:

    f2nml src/*f90 params_default.nml --groups geometry dynamics --type-suffix _t  
    
  • create src/ioparams.f90 from namelist (to know which types to search for) AND source code (not to rely on namelist parsing to determine individual variable types, and to include additional type control_type):

    nml2f90 params_default.nml src/ioparams.f90 --src src/*f90 \
    --type-suffix _t  \         #  map namelist block onto fortran types
    --include-groups control --type-map '{"control":"control_type"}'  \    # include a type not in namelist
    --io-nml --command-line   # features to include in ioparams.f90
    

New way?

It would be cleaner to have instead a single code parsing command that looks for the appropriate types, and provide additional information depending on the features to add. For example a new script ioparams that could handle several cases via a --to argument (supplemented by --fmt for ambiguous cases):

  • parse source code and create I/O routine:

    ioparams --src src/*f90  --to src/ioparams.f90 --command-line --io-nml  $(TYPES)
    
  • create the default namelist according to the source code

    ioparams --src src/*f90 --to params_default.nml  $(TYPES)
    

where $(TYPES) indicates the required input information about which types to search for in the code, and how to map it to namelist or command-line blocks.

In the current setting, you would define TYPES (in the Makefile) beforehand as:

    TYPES = --groups geometry dynamics control  --type-suffix _t   \
        --type-map '{"control":"control_type"}' 

Note that --groups + --type-suffix is a convenient way of mapping from groups (namelist block, command-line groups) to derived types to search for in the code, but this could evolve, too.

Perspectives

This new ioparams utility could actually build on other libraries and formats, like json-fortran (param file in json), flap (command-line) as is already the case with nml, each being a new feature.

So this piece of code is handy and has a potential to evolve. Just need to clean it up to make it more sexy and easy to use.

This will probably involve changing name, likely ioparams !

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.