{"id":18847822,"url":"https://github.com/jacobwilliams/fortran_function_parser","last_synced_at":"2026-02-16T12:38:31.121Z","repository":{"id":16591020,"uuid":"78370882","full_name":"jacobwilliams/fortran_function_parser","owner":"jacobwilliams","description":"Modern Fortran function parser. An update of \"fparser\" by Roland Schmehl","archived":false,"fork":false,"pushed_at":"2022-06-27T15:28:11.000Z","size":1030,"stargazers_count":33,"open_issues_count":4,"forks_count":6,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-10-08T19:18:26.571Z","etag":null,"topics":["expression-parser","fortran","function-parser"],"latest_commit_sha":null,"homepage":"","language":"Fortran","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jacobwilliams.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-01-08T21:13:57.000Z","updated_at":"2025-03-23T00:29:54.000Z","dependencies_parsed_at":"2022-07-24T20:32:28.326Z","dependency_job_id":null,"html_url":"https://github.com/jacobwilliams/fortran_function_parser","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/jacobwilliams/fortran_function_parser","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacobwilliams%2Ffortran_function_parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacobwilliams%2Ffortran_function_parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacobwilliams%2Ffortran_function_parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacobwilliams%2Ffortran_function_parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jacobwilliams","download_url":"https://codeload.github.com/jacobwilliams/fortran_function_parser/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacobwilliams%2Ffortran_function_parser/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29507912,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-16T09:05:14.864Z","status":"ssl_error","status_checked_at":"2026-02-16T08:55:59.364Z","response_time":115,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["expression-parser","fortran","function-parser"],"created_at":"2024-11-08T03:09:45.266Z","updated_at":"2026-02-16T12:38:31.102Z","avatar_url":"https://github.com/jacobwilliams.png","language":"Fortran","readme":"![fortran_function_parser](media/logo.png)\n============\n\n### Status\n\n[![GitHub release](https://img.shields.io/github/release/jacobwilliams/fortran_function_parser.svg)](https://github.com/jacobwilliams/fortran_function_parser/releases/latest)\n[![Build Status](https://github.com/jacobwilliams/fortran_function_parser/actions/workflows/CI.yml/badge.svg)](https://github.com/jacobwilliams/fortran_function_parser/actions)\n[![codecov](https://codecov.io/gh/jacobwilliams/fortran_function_parser/branch/master/graph/badge.svg)](https://codecov.io/gh/jacobwilliams/fortran_function_parser)\n[![last-commit](https://img.shields.io/github/last-commit/jacobwilliams/fortran_function_parser)](https://github.com/jacobwilliams/fortran_function_parser/commits/master)\n\n### Description\n\nThis function parser module is intended for applications where a set of\nmathematical fortran-style expressions is specified at runtime and is\nthen evaluated for a large number of variable values. This is done by\ncompiling the set of function strings into byte code, which is\ninterpreted efficiently for the various variable values.\n\nThis code is a modernized version of [fparser](http://fparser.sourceforge.net) (v1.1), a Fortran 95 function parser (v1.1) by [Roland Schmehl](roland.schmehl@alumni.uni-karlsruhe.de). The function parser concept is based on a C++ class library written by Juha Nieminen \u003cwarp@iki.fi\u003e available from [here](http://warp.povusers.org/FunctionParser/). The original code has been updated to Fortran 2008 by Jacob Williams. Development continues on [GitHub](https://github.com/jacobwilliams/fortran_function_parser).\n\n### Building\n\nThe library can be built with the [Fortran Package Manager](https://github.com/fortran-lang/fpm) using the provided `fpm.toml` file like so:\n\n```bash\nfpm build --release\n```\n\nBy default, the library is built with double precision (`real64`) real values. Explicitly specifying the real kind can be done using the following preprocessor flags:\n\nPreprocessor flag | Kind  | Number of bytes\n----------------- | ----- | ---------------\n`REAL32`  | `real(kind=real32)`  | 4\n`REAL64`  | `real(kind=real64)`  | 8\n`REAL128` | `real(kind=real128)` | 16\n\nFor example, to build a single precision version of the library, use:\n\n```\nfpm build --profile release --flag \"-DREAL32\"\n```\n\nTo use `fortran_function_parser` within your fpm project, add the following to your `fpm.toml` file:\n\n```toml\n[dependencies]\nfortran_function_parser = { git=\"https://github.com/jacobwilliams/fortran_function_parser.git\" }\n```\n\nOr, to use a specific version:\n\n```toml\n[dependencies]\nfortran_function_parser = { git=\"https://github.com/jacobwilliams/fortran_function_parser.git\", tag = \"1.1.0\" }\n```\n\n### Documentation\n\nThe latest API documentation can be found [here](https://jacobwilliams.github.io/fortran_function_parser/). This was generated from the source code using [FORD](https://github.com/Fortran-FOSS-Programmers/ford).\n\n### Basic usage\n\n#### Module Import\n\nIn all program units where you want to use the function parser\nyou must import the module by:\n\n```fortran\nuse function_parser\n```\n\nThis command imports only 3 public types: `fparser`, `fparser_array`, and\n`list_of_errors`, which are explained in the following. The remainder of the\nmodule is hidden to the calling program.\n\n#### Function parsing\n\nA single function string `funcstr` can be parsed (checked and compiled) into\nbytecode by calling the `fparser` class method subroutine `parse`:\n\n```fortran\ncall me%parse(funcstr, var, case_sensitive)\n```\n\nThe variable names as they appear in the string `funcstr` have to be passed\nin the one-dimensional string array `var` (zero size of `var` is acceptable).\nThe number of variables is implicitly passed by the dimension of this array.\nFor some notes on the syntax of the function string see below.\n\nTo parse an array of function strings, you can use the `fparser_array` class\nmethod `parse` in a similar manner.\n\n#### Function evaluation\n\nThe function value is evaluated for a specific set of variable values\nby calling the `fparser` class method subroutine `evaluate`:\n\n```fortran\ncall me%evaluate(val, res)\n```\n\nThe variable values are passed in the one-dimensional array `val` which must\nhave the same dimension as array `var`.\n\nTo evaluate an array of function strings, you can use the `fparser_array` class\nmethod `evaluate` in a similar manner.\n\n#### Cleanup\n\nTo free the memory and destroy a variable of type `fparser` or `fparser_array`,\nuse the `destroy` method:\n\n```fortran\ncall me%destroy()\n```\n\n### Error handling\n\nErrors can be reported by both the `parse` and `evaluate`\nclass methods. To check for errors, use the `error` method, and to print them use the `print_errors` method:\n\n```fortran\n if (me%error()) then\n     me%print_errors(output_unit)\n end if\n```\n\nAn error in the function parsing step leads to a detailed error message\n(type and position of error). An error during function evaluation returns a function value of 0.0.\n\n### Function string syntax\n\nAlthough they have to be passed as array elements of the same declared\nlength (Fortran restriction), the variable names can be of arbitrary\nactual length for the parser. By default, parsing for variables is case insensitive,\nbut case sensitive evaluation is also an option.\n\nThe syntax of the function string is similar to the Fortran convention.\nMathematical Operators recognized are `+,` `-,` `*,` `/,` `**` or alternatively `^,`\nwhereas symbols for brackets must be `()`.\n\nThe function parser recognizes the (single argument) Fortran intrinsic\nfunctions:\n* [`abs`](https://fortran-lang.org/learn/intrinsics/ABS), [`acos`](https://fortran-lang.org/learn/intrinsics/ACOS), [`asin`](https://fortran-lang.org/learn/intrinsics/ASIN), [`atan`](https://fortran-lang.org/learn/intrinsics/ATAN), [`atan2`](https://fortran-lang.org/learn/intrinsics/ATAN2), [`ceiling`](https://fortran-lang.org/learn/intrinsics/CEILING), [`cos`](https://fortran-lang.org/learn/intrinsics/COS), [`cosh`](https://fortran-lang.org/learn/intrinsics/COSH), [`exp`](https://fortran-lang.org/learn/intrinsics/EXP), [`floor`](https://fortran-lang.org/learn/intrinsics/FLOOR), [`gamma`](https://fortran-lang.org/learn/intrinsics/GAMMA), [`hypot`](https://fortran-lang.org/learn/intrinsics/HYPOT), [`log`](https://fortran-lang.org/learn/intrinsics/LOG), [`log10`](https://fortran-lang.org/learn/intrinsics/LOG10), [`max`](https://fortran-lang.org/learn/intrinsics/MAX), [`min`](https://fortran-lang.org/learn/intrinsics/MIN), [`mod`](https://fortran-lang.org/learn/intrinsics/MOD), [`modulo`](https://fortran-lang.org/learn/intrinsics/MODULO), [`sign`](https://fortran-lang.org/learn/intrinsics/SIGN), [`sin`](https://fortran-lang.org/learn/intrinsics/SIN), [`sinh`](https://fortran-lang.org/learn/intrinsics/SINH), [`sqrt`](https://fortran-lang.org/learn/intrinsics/SQRT), [`tan`](https://fortran-lang.org/learn/intrinsics/TAN), [`tanh`](https://fortran-lang.org/learn/intrinsics/TANH)\n\nIn addition, the following zero-argument function:\n* `pi` -- Returns the value of $\\pi$\n\nAnd the three-argument function:\n* `if` -- Logical comparision function. The syntax is: `if(expression, value if true, value if false)`, where 0.0 is false, and any other real value is true.\n\nParsing for functions is always case INsensitive.\n\nOperations are evaluated in the correct order:\n\n* `()      `    expressions in brackets first\n* `-A      `    unary minus (or plus)\n* `A**B A^B`    exponentiation (`A` raised to the power `B`)\n* `A*B  A/B`    multiplication and division\n* `A+B  A-B`    addition and subtraction\n\nThe function string can contain integer or real constants. To be recognized\nas explicit constants these must conform to the format\n\n`[+|-][nnn][.nnn][e|E|d|D[+|-]nnn]`\n\nwhere `nnn` means any number of digits. The mantissa must contain at least\none digit before or following an optional decimal point. Valid exponent\nidentifiers are 'e', 'E', 'd' or 'D'. If they appear they must be followed\nby a valid exponent.\n\n### Other codes\n\nThere are various other expression parsers out there written in Fortran:\n\n```mermaid\nflowchart TB\n\tfparser[\u003ca href='http://fparser.sourceforge.net'\u003efparser\u003c/a\u003e]\n\tfparser--\u003eFortranParser[\u003ca href='https://github.com/jacopo-chevallard/FortranParser'\u003eFortranParser\u003c/a\u003e]\n\tfparser--\u003efortran_function_parser[\u003ca href='https://github.com/jacobwilliams/fortran_function_parser'\u003efortran_function_parser\u003c/a\u003e]\n\tfortran_parser--\u003efortran_script[\u003ca href='https://github.com/sdm900/fortran_script'\u003efortran_script\u003c/a\u003e]\n\tffp[\u003ca href='http://www.labfit.net/functionparser.htm'\u003eFortran Function Parser\u003c/a\u003e]\n\tfeq-parse[\u003ca href='https://github.com/FluidNumerics/feq-parse'\u003efeq-parse\u003c/a\u003e]\n\tfortran_parser[\u003ca href='https://github.com/sdm900/fortran_parser'\u003efortran_parser\u003c/a\u003e]\n\tM_calculator[\u003ca href='https://github.com/urbanjost/M_calculator'\u003eM_calculator\u003c/a\u003e]\n\tM_calculator--\u003ecompute[\u003ca href='https://github.com/urbanjost/compute'\u003ecompute\u003c/a\u003e]\n\n```\n\n* [fparser](http://fparser.sourceforge.net) -- Original Fortran 95 function parser by Roland Schmehl.\n* [FortranParser](https://github.com/jacopo-chevallard/FortranParser) -- Another refactoring of the original `fparser` code by Jacopo Chevallard.\n* [Fortran Function Parser](http://www.labfit.net/functionparser.htm) -- An entirely different code by Wilton and Ivomar, 10/01/2007 (GitHub mirror [here](https://github.com/jacobwilliams/ffp)).\n* [feq-parse](https://github.com/FluidNumerics/feq-parse) -- Fortran Equation Parser from FluidNumerics.\n* [fortran_parser](https://github.com/sdm900/fortran_parser) -- Fortran Equation Parser from Stuart Midgley.\n* [M_calculator](https://github.com/urbanjost/M_calculator) -- Parse Fortran-like double precision scalar expressions from urbanjost\n\n### See also\n\n* [Application of Modern Fortran to Spacecraft Trajectory Design and Optimization](https://ntrs.nasa.gov/api/citations/20180000413/downloads/20180000413.pdf) (AIAA 2018-1451) describes a method of constructing a Fortran expression parser using binary syntax trees.\n* [Dynamic Eval for Fortran](https://github.com/j3-fortran/fortran_proposals/issues/126) Suggestion to add dynamic expression evaluation to the Fortran language (don't hold your breath).","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjacobwilliams%2Ffortran_function_parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjacobwilliams%2Ffortran_function_parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjacobwilliams%2Ffortran_function_parser/lists"}