A Modern Fortran-based Parser
November 2, 2021 ยท View on GitHub
| Status | |
|---|---|
| Info | |
| License |
This repository contains a modern Fortran-based input file parser which can be used within an MPI-enabled Fortran program. It uses a heavily modified libfdf library. More about this library in the Licence file.
Get the code
The library is included in this repository as a submodule. To clone the entire project, do
git clone git@github.com:neelravi/mpi-libfdf-parser.git
Compilation
The project contains two folders (a) modified-libfdf and (b) parser.
Compile and install the modified-libfdf using the following set of commands
./configure --prefix=/usr/local FC=ifort CC=icc
make
sudo make install
In the parser folder, link the modified libfdf library with the interface Fortran file.
ifort -c m_periodic_table.F90 m_keywords.F90
ifort interface.F90 m_keywords.F90 m_periodic_table.F90 /usr/local/lib/libfdf.a
Integrate parser in your code
Just include the interface.F90 file and the keyword declaration module files in the existing Makefile of your code.
Features of the parser (including inheritance from libfdf)
-
Blank lines and lines starting with # are ignored.
-
The order of keyword-value pairs does not matter
-
Spaces and tabs are ignored; keyword-value pairs are parsed in a free-form.
-
Keywords are case insensitive.
-
A default value can be set for keywords not present in the input file.
-
Large data can be parsed using the %block structure.
-
Multiple keyword-value pairs can be clubbed together in a %module structure.
Syntax
-
Include another input file for parser to read using:
%include global.inp -
Include a data file for parser to read using:
load label filename -
Here, depending upon the label, parser will provide the filename. For example,
load basis cc-pvtz.gbs -
Read molecular coordinates directly from the input file using
%block molecule 12 #benzene comment C 0.00000 1.40272 0 H 0.00000 2.49029 0 C -1.21479 0.70136 0 H -2.15666 1.24515 0 C -1.21479 -0.70136 0 H -2.15666 -1.24515 0 C 0.00000 -1.40272 0 H 0.00000 -2.49029 0 C 1.21479 -0.70136 0 H 2.15666 -1.24515 0 C 1.21479 0.70136 0 H 2.15666 1.24515 0 %endblock -
Read molecular coordinates from an external .xyz file using
%block molecule < benzene.xyz -
Group certain keywords using the %module construct
%module DMC tau = 0.04 etrial = -15 Ha %endmodule -
Logical variables accept
true,TRUE,T,.true.as valid keywords forTrue. Thefdf_booleanfunction can also take "1" as true and "0" as false from the input.optimize_wavefunction true -
Single and Double precision numbers along with numbers in scientific format can be read using the
fdf_get()function. The second number in the bracket denotes the default value.energy_tol = fdf_get('energy_tol', 0.00001d0) -
Floats/integers/strings/booleans can be parsed generically using the interface
fdf_get()function. Strings are limited to 132 characters per line.sr_tau = fdf_get('sr_tau', 0.025d0)nspin1 = fdf_get('nspin1', 1)opt_method = fdf_get('opt_method', "sr_n")multiple_adiag = fdf_get('multiple_adiag', .false.) -
Units can be specified to variables. Unit conversion is possible at the parsing.
If the input file has
etrial = -15 Haentry, theetrialvariable can be assigned values using thefdf_physicalfunction with unit conversion.etrial = fdf_physical('etrial', -20.d0, 'eV') -
List of public functions available for parsing the data:
Initiate
fdf_initfdf_shutdownSingle data
fdf_getfdf_integerfdf_singlefdf_doublefdf_stringfdf_booleanfdf_physicalfdf_convfacfdf_load_filenameLists (data enclosed in [])
fdf_islistfdf_islintegerfdf_islrealfdf_listfdf_lintegerfdf_ldoubleReturns the string associated with a mark line
fdf_getlineTest if a label is defined
fdf_definedfdf_isphysicalfdf_isblockfdf_load_definedAllow to overwrite things in the FDF
fdf_overwritefdf_removelabelfdf_addlineBlock reading (processing each line of data)
fdf_block, fdf_block_linecountfdf_bline, fdf_bbackspace, fdf_brewind, fdf_bclosefdf_bnintegers, fdf_bnreals, fdf_bnvalues, fdf_bnnames, fdf_bntokensfdf_bintegers, fdf_breals, fdf_bvalues, fdf_bnames, fdf_btokensfdf_bboolean, fdf_bphysicalfdf_bnlists, fdf_bnilists, fdf_bnrlists, fdf_bnvlistsfdf_bilists, fdf_brlists, fdf_bvlistsMatch, search over blocks, and destroy block structure
fdf_bmatch, fdf_bsearch, fdf_substring_searchfdf_setoutput, fdf_setdebug
Demonstration
In the parser folder, we have included a sample interface.F90 and m_keywords.F90 files.
In the interface.F90 file, we have demonstrated how keyword-values pairs, simple data blocks,
and data from external files can be read easily.
Contributors
2021- Ravindra Shinde (@neelravi) r.l.shinde@utwente.nl
2007-2014 Based on the LibFDF library originally designed by Alberto Garcia and Jose Soler, and reimplemented by Raul de la Cruz (Barcelona Supercomputer Center).