{"id":17694175,"url":"https://github.com/vmagnin/fundamental_constants","last_synced_at":"2026-02-07T00:35:42.081Z","repository":{"id":139624209,"uuid":"347415901","full_name":"vmagnin/fundamental_constants","owner":"vmagnin","description":"Fortran modules with the CODATA fundamental physical constants, generated by a Python script.","archived":false,"fork":false,"pushed_at":"2025-05-05T09:12:39.000Z","size":157,"stargazers_count":14,"open_issues_count":0,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-07-24T22:29:19.101Z","etag":null,"topics":["codata","fortran","fortran-package-manager","nist"],"latest_commit_sha":null,"homepage":"","language":"Fortran","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vmagnin.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2021-03-13T16:07:53.000Z","updated_at":"2025-05-05T09:12:42.000Z","dependencies_parsed_at":"2025-07-24T18:31:39.215Z","dependency_job_id":"78aa3d3b-f71a-49ee-9306-cc234b4e1a95","html_url":"https://github.com/vmagnin/fundamental_constants","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/vmagnin/fundamental_constants","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vmagnin%2Ffundamental_constants","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vmagnin%2Ffundamental_constants/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vmagnin%2Ffundamental_constants/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vmagnin%2Ffundamental_constants/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vmagnin","download_url":"https://codeload.github.com/vmagnin/fundamental_constants/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vmagnin%2Ffundamental_constants/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29182040,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-06T23:15:33.022Z","status":"ssl_error","status_checked_at":"2026-02-06T23:15:09.128Z","response_time":59,"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":["codata","fortran","fortran-package-manager","nist"],"created_at":"2024-10-24T13:48:04.063Z","updated_at":"2026-02-07T00:35:42.042Z","avatar_url":"https://github.com/vmagnin.png","language":"Fortran","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CODATA fundamental physical constants\n\n**Fortran modules with the CODATA fundamental physical constants, generated by a Python script from the NIST website.**\n\nThe `nist.py` Python script downloads the CODATA recommended values (latest by default), available as an ASCII file on the NIST website:\n\nhttps://physics.nist.gov/cuu/Constants/Table/allascii.txt\n\nand generates a Fortran `module CODATA_constants` in the file `src/CODATA_constants.f90`. The 2022 CODATA set contains 355 constants. The next set (2026 CODATA adjustment) should be published in 2027 or 2028.\n\nIt also generates a Fortran program `test/test.f90` which uses that module to generate a text file reproducing the two first columns, with (nearly) the same formatting as in the CODATA NIST file. It helps me check every digit to validate the result.\n\nDon't expect great features, I will keep it simple. See the References section at the end of this page for more elaborate projects.\n\n# Ready to use validated Fortran modules\n\nIn the `src/` directory, you will find for each recent CODATA sets:\n\n- the corresponding validated `CODATA_????_constants.f90` module,\n- the `fortran_generated_????.txt` file generated using this module. A graphical diff tool was used to verify that the numbers printed in that file are identical to numbers in the NIST file, which validates the Fortran module,\n- the `CODATA_latest_constants.f90` module, if you are only interested by the latest set.\n\nThere are three ways to use this project:\n- as a fpm (Fortran Package Manager) dependency by adding in your `fpm.toml` file:\n\n```toml\n[dependencies]\nfundamental_constants = { git=\"https://github.com/vmagnin/fundamental_constants.git\" }\n```\n\n- or by copying the module `.f90` files you need in your project,\n- or just the few lines you need (the project is under MIT license).\n\n\n## Using the Fortran modules\n\nThe constant names in the modules are quite long:\n\n```Fortran\nmodule CODATA_latest_constants\n  use, intrinsic :: iso_fortran_env, only: wp=\u003ereal64\n  implicit none\n\n  real(wp), parameter :: alpha_particle_electron_mass_ratio = 7294.29954171_wp ! 0.000 000 17  \n  real(wp), parameter :: alpha_particle_mass = 6.6446573450e-27_wp ! 0.000 000 0021 e-27  kg\n  real(wp), parameter :: alpha_particle_mass_energy_equivalent = 5.9719201997e-10_wp ! 0.000 000 0019 e-10  J\n...\n```\n\nYou can rename them upon import like this:\n\n```fortran\nuse CODATA_latest_constants, only: c=\u003espeed_of_light_in_vacuum\n```\n\nYou can create your own short module with a `use CODATA_latest_constants` statement and put into it your renamed favourite constants, accordingly to what you generally need in your scientific field.\n\nNote also that the names of some constants may vary from one CODATA adjustement to another. Our project does not track those (rare) modifications.\n\nYou can cite:\n\n\u003e Mohr, Peter J., David B. Newell, Barry N. Taylor, and Eite Tiesinga. “CODATA Recommended Values of the Fundamental Physical Constants: 2022.” Reviews of Modern Physics 97, no. 2 (April 30, 2025): 025002. https://doi.org/10.1103/RevModPhys.97.025002.\n\nFree download: https://tsapps.nist.gov/publication/get_pdf.cfm?pub_id=958143\n\n## Why several modules?\n\nMost of the time you will use the latest values. But if you need to reproduce exactly the results obtained several years ago, you may need to use the corresponding CODATA set. It can be also useful if your project contains tests that expect a very precise numerical result.\n\n\n# Generating a new Fortran module\n\n## Default options\n\nFrom the project root directory, type:\n\n```bash\n$ ./nist.py\nGenerating the src/CODATA_constants.f90 file using the recommended 2022 values:\nhttps://physics.nist.gov/cuu/Constants/Table/allascii.txt\n355 constants written\n34600 bytes\n```\n\n## Options of the Python script\n\n```bash\n$ ./nist.py --help\nusage: nist.py [-h] [-y {2010,2014,2018,2022}] [-d] [-v]\n\nDownloads CODATA recommended values of physical constants from NIST website and generates a Fortran module.\n\noptions:\n  -h, --help            show this help message and exit\n  -y {2010,2014,2018,2022}\n                        CODATA values: 2010, 2014, 2018 or 2022\n  -d                    Delete calculated values (...)\n  -v                    Version\n\nSources: \u003chttps://github.com/vmagnin/fundamental_constants\u003e\n```\n\nBy default latest values are downloaded. But you can force the year with the `-y` option.\n\nBy default, CODATA calculated values (containing `'...'`) are kept. But you can delete them with the `-d` option if you prefer to calculate them in your program, in order to have more decimals.\n\n\n# Validating the values in the Fortran module\n\nIf you have the fpm Fortran Package Manager, build and launch the test:\n\n```bash\n$ fpm test\n[...]\n Do you know this constant with so many zeros?\n0100000110110001110111100111100001001010000000000000000000000000\n Oh sorry, you're that kind of biped with 10 digits?\n   299792458.00000000     \n Some other constants:\n   6.0221407599999999E+023\n   1.3806490000000001E-023\n   1.6021766339999999E-019\n 4.500 3878060E-10        \n 2808.92113298            \n 1234.123 456 78          \n ------------------------------------------------\n Writing the fortran_generated_????.txt test file\n```\n\nA graphical diff tool, like `meld`, can be used to compare the `fortran_generated_????.txt` file with the NIST file, in order to validate the Fortran module:\n\n```shell\n$ meld allascii_2022.txt fortran_generated_2022.txt\n```\n\n Most constants are written exactly as in the NIST file. A few constants are written differently because the NIST file don't use the classical scientific format: for example, the molar mass of carbon-12 is written 1.200 000 001 26 e-2 in our file but 12.000 000 0126 e-3 in the NIST file. But it is quick to verify that those values are correct. Some of the values in the NIST file can be calculated from other constants and are terminated by `'...'` in the NIST file: note that their values in the Fortran module are not calculated, but have the same number of digits as in the NIST file.\n\nYou can use alternatively the `build.sh` script to build the `build/runTests` executable.\n\n\n# References\n* Origin of this project: https://fortran-lang.discourse.group/t/physical-constants/822\n* About CODATA:\n    * https://physics.nist.gov/cuu/Constants/bibliography.html\n    * https://en.wikipedia.org/wiki/Committee_on_Data_for_Science_and_Technology\n* NIST website: https://physics.nist.gov/cuu/Constants/\n* If you need a more complete project around constants, you may be interested by:\n    * https://github.com/MilanSkocic/codata\n        * Will soon be integrated in the Fortran stdlib: https://github.com/fortran-lang/stdlib/pull/800\n    * https://gitlab.com/apthorpe/stdlib-codata\n    * https://github.com/MolSSI/QCElemental\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvmagnin%2Ffundamental_constants","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvmagnin%2Ffundamental_constants","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvmagnin%2Ffundamental_constants/lists"}