mirror of
https://gitlab.com/scemama/EZFIO.git
synced 2024-09-01 01:03:43 +02:00
Migration from Sourceforge
This commit is contained in:
parent
29a999c0f8
commit
0827fb9f54
280
LICENSE
Normal file
280
LICENSE
Normal file
@ -0,0 +1,280 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
55
Makefile
Normal file
55
Makefile
Normal file
@ -0,0 +1,55 @@
|
||||
# EZFIO is an automatic generator of I/O libraries
|
||||
# Copyright (C) 2009 Anthony SCEMAMA, CNRS
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Anthony Scemama
|
||||
# LCPQ - IRSAMC - CNRS
|
||||
# Universite Paul Sabatier
|
||||
# 118, route de Narbonne
|
||||
# 31062 Toulouse Cedex 4
|
||||
# scemama@irsamc.ups-tlse.fr
|
||||
|
||||
include version
|
||||
include make.config
|
||||
|
||||
.PHONY: default clean distclean archive configure
|
||||
|
||||
default: make.config
|
||||
- bash -c "[[ -e lib/libezfio.a ]] && rm $$PWD/lib/*"
|
||||
@echo Compiling library && make -C $$PWD/src static
|
||||
@echo Building Python module && make -C $$PWD/src python
|
||||
|
||||
clean:
|
||||
- bash -c "[[ -e lib/libezfio.a ]] && rm $$PWD/lib/*"
|
||||
- bash -c "[[ -e Python/ezfio.py ]] && rm $$PWD/Python/*"
|
||||
- make -C $$PWD/src veryclean
|
||||
|
||||
distclean: clean
|
||||
- rm -rf autom4te.cache config.status config.log make.config
|
||||
|
||||
archive: distclean
|
||||
git archive --format=tar HEAD > EZFIO.$(VERSION).tar
|
||||
mkdir EZFIO ; cd EZFIO ; tar -xvf ../EZFIO.$(VERSION).tar
|
||||
rm EZFIO.$(VERSION).tar
|
||||
tar -zcvf EZFIO.$(VERSION).tar.gz EZFIO
|
||||
rm -rf EZFIO
|
||||
|
||||
configure: make.config.in configure.ac
|
||||
autoconf
|
||||
|
||||
make.config:
|
||||
./configure --host=dummy
|
||||
|
0
Ocaml/.empty
Normal file
0
Ocaml/.empty
Normal file
0
Python/.empty
Normal file
0
Python/.empty
Normal file
86
README
Normal file
86
README
Normal file
@ -0,0 +1,86 @@
|
||||
======================================================================
|
||||
EZFIO
|
||||
======================================================================
|
||||
|
||||
Author: A. Scemama, LCPQ-IRSAMC, CNRS-Universite Paul Sabatier
|
||||
scemama@irsamc.ups-tlse.fr
|
||||
|
||||
== About EZFIO ==
|
||||
|
||||
EZFIO is the Easy Fortran I/O library. With EZFIO, your data is organized
|
||||
in a file system inside a main directory. This main directory contains
|
||||
subdirectories, which contain files. Each file corresponds to a data. For
|
||||
atomic data the file is a plain text file, and for array data the file is a
|
||||
gzipped text file.
|
||||
|
||||
|
||||
== Building a library ==
|
||||
|
||||
Your EZFIO library is built according to the definitions given in the
|
||||
files of the 'config' directory. A configuration file can be, for example:
|
||||
---
|
||||
|
||||
system
|
||||
title character*(128)
|
||||
num_elec integer = system_num_alpha + system_num_beta
|
||||
num_alpha integer
|
||||
num_beta integer
|
||||
|
||||
geometry
|
||||
num_atom integer
|
||||
nuc_energy double precision
|
||||
label character*(32) (geometry_num_atom)
|
||||
atomic_number integer (geometry_num_atom)
|
||||
charge double precision (geometry_num_atom)
|
||||
coord double precision (3,geometry_num_atom)
|
||||
|
||||
---
|
||||
|
||||
A subdirectory is defined by its name at the beginning of a new line. The
|
||||
data contained in this subdirectory is defined by the triplet
|
||||
(name,type,dimension), leaving at least one white space at the beginning of the
|
||||
line.
|
||||
If the dimension of an array is a data defined in the file, its name can be
|
||||
used as <name of the subdirectory>_<name of the data>. For example, the
|
||||
dimension '(geometry_num_atom)' uses the data 'num_atom' of subdirectory
|
||||
'geometry'.
|
||||
A data can also be the result of a simple operation. In that case, the
|
||||
simple operation is written after an '=' symbol (as for 'num_elec'). In
|
||||
that case, the data is read_only.
|
||||
|
||||
Once your configuration file is ready, run 'make' and your library will be
|
||||
built.
|
||||
|
||||
== Using the library ==
|
||||
|
||||
In the following, we will call 'EZFIO file' the main directory containing the
|
||||
EZFIO data.
|
||||
|
||||
Only one EZFIO file can be manipulated at a time. To select a file, use:
|
||||
character*(64) :: filename
|
||||
call ezfio_set_file(filename)
|
||||
To get the name of the current used EZFIO file, use
|
||||
character*(64) :: filename
|
||||
call ezfio_get_filename(filename)
|
||||
|
||||
For each data, 3 subroutines are created.
|
||||
<dir> is the name of the subdirectory which contains the data and
|
||||
<data> is the name of the data.
|
||||
|
||||
* subroutine ezfio_has_<dir>_<data> (result)
|
||||
sets result to .True. if the data exists in the EZFIO file, .False. otherwise.
|
||||
|
||||
* subroutine ezfio_set_<dir>_<data> (source)
|
||||
writes the source data to the EZFIO file.
|
||||
|
||||
* subroutine ezfio_get_<dir>_<data> (destination)
|
||||
reads the data from the EZFIO file to the destination.
|
||||
|
||||
For safety, a read-only attribute can be set to the file by
|
||||
call ezfio_set_read_only(.True.)
|
||||
or inquired by
|
||||
logical :: is_read_only
|
||||
call ezfio_is_read_only(is_read_only)
|
||||
|
||||
|
||||
|
340
README.rst
Normal file
340
README.rst
Normal file
@ -0,0 +1,340 @@
|
||||
EZFIO
|
||||
=====
|
||||
|
||||
EZFIO is the Easy Fortran I/O library generator. It generates
|
||||
automatically an I/O library from a simple configuration file. The
|
||||
produced library contains Fortran subroutines to read/write the data
|
||||
from/to disk, and to check if the data exists.
|
||||
A Python and an Ocaml API are also provided.
|
||||
|
||||
With EZFIO, the data is organized in a file system inside a main
|
||||
directory. This main directory contains subdirectories, which contain
|
||||
files. Each file corresponds to a data. For atomic data the file is a
|
||||
plain text file, and for array data the file is a gzipped text file.
|
||||
|
||||
Download
|
||||
========
|
||||
|
||||
The following packages are needed:
|
||||
|
||||
* `IRPF90 <http://irpf90.ups-tlse.fr>`_
|
||||
* `Python <http://www.python.org>`_
|
||||
|
||||
The latest version can be downloaded `here <http://qmcchem.ups-tlse.fr/files/scemama/EZFIO.latest.tar.gz>`_.
|
||||
|
||||
Tutorial
|
||||
========
|
||||
|
||||
In this example, we will write a Fortran program which computes
|
||||
properties of a molecule. The molecule is described as point charges in
|
||||
the 3D space.
|
||||
|
||||
Preparation of the library
|
||||
--------------------------
|
||||
|
||||
Create an empty directory for your project and unpack the ``EZFIO.tar.gz`` file in this directory. This directory now contains:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ ls
|
||||
EZFIO/
|
||||
|
||||
Get into the ``EZFIO`` directory and run:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ ./configure
|
||||
|
||||
Now, configure the library to produce the desired suboutines. Get into
|
||||
the ``config`` directory and create a new file ``test.config``
|
||||
containing::
|
||||
|
||||
molecule
|
||||
num_atoms integer
|
||||
mass real (molecule_num_atoms)
|
||||
coord real (3,molecule_num_atoms)
|
||||
|
||||
properties
|
||||
mass real = sum(molecule_mass)
|
||||
center_of_mass real (3)
|
||||
|
||||
|
||||
In this example, ``molecule`` and ``properties`` are containers of data.
|
||||
Those are defined in the config file by their name at the beginning of a
|
||||
new line.
|
||||
Each data contained inside a container is characterized by a triplet
|
||||
(name,type,dimension), preceded by at least one white space at the
|
||||
beginning of the line.
|
||||
|
||||
If the dimension of an array is a data, the name of the data can be used
|
||||
as ``<container>_<data>`` in the definition of the dimension. For
|
||||
example, the dimension (``molecule_num_atoms``) uses the data
|
||||
``num_atoms`` of container ``molecule``.
|
||||
|
||||
Data can also be the result of a simple operation. In that case, the
|
||||
simple operation is written after an = symbol (as for ``mass`` in the
|
||||
``properties`` container). In that case, the data is read-only.
|
||||
|
||||
Once your configuration file is ready, run ``make`` and your library
|
||||
will be built.
|
||||
|
||||
Building the library
|
||||
--------------------
|
||||
|
||||
Now, go back to the EZFIO root directory, and run:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ make
|
||||
|
||||
The ``lib`` directory now contains the shared library
|
||||
(``libezfio.so``), the static library (``libezfio.a``), and a static
|
||||
library for use under the IRPF90 environment (``libezfio_irp.a``).
|
||||
The ``Python`` directory contains the Python module for the use of the library in Python.
|
||||
|
||||
Using the produced library
|
||||
--------------------------
|
||||
|
||||
In the following, we will call 'EZFIO file' the main directory
|
||||
containing the EZFIO data.
|
||||
|
||||
All the produced libraries contain the following subroutines:
|
||||
|
||||
subroutine ezfio_set_read_only(ro)
|
||||
If ``ro`` is .True., the read-only attribute is set. It will be
|
||||
impossible to write to the EZFIO file.
|
||||
|
||||
subroutine ezfio_is_read_only(ro)
|
||||
Returns the value of the read_only attribute to ``ro``.
|
||||
|
||||
subroutine ezfio_set_file(filename)
|
||||
Only one EZFIO can be manipulated at a time. This subroutine selects
|
||||
which file will be manipulated.
|
||||
|
||||
subroutine ezfio_get_filename(fname)
|
||||
Returns the name of the EZFIO file which is currently manipulated.
|
||||
|
||||
For each data, 3 subroutines are created.
|
||||
<dir> is the name of the container which contains the data and
|
||||
<data> is the name of the data.
|
||||
|
||||
subroutine ezfio_has_<dir>_<data> (has_it)
|
||||
``has_it`` is .True. if the data exists in the EZFIO file, .False. otherwise.
|
||||
|
||||
subroutine ezfio_set_<dir>_<data> (source)
|
||||
writes the source data to the EZFIO file.
|
||||
|
||||
subroutine ezfio_get_<dir>_<data> (destination)
|
||||
reads the data from the EZFIO file to the destination.
|
||||
|
||||
With our example, the library contains the following subroutines:
|
||||
|
||||
.. code-block:: fortran
|
||||
|
||||
subroutine ezfio_set_read_only(ro)
|
||||
subroutine ezfio_is_read_only(ro)
|
||||
subroutine ezfio_set_file(filename)
|
||||
subroutine ezfio_get_filename(filename)
|
||||
|
||||
subroutine ezfio_set_molecule_num_atoms(num_atoms)
|
||||
subroutine ezfio_get_molecule_num_atoms(num_atoms)
|
||||
subroutine ezfio_has_molecule_num_atoms(has_it)
|
||||
|
||||
subroutine ezfio_set_molecule_mass(mass)
|
||||
subroutine ezfio_get_molecule_mass(mass)
|
||||
subroutine ezfio_has_molecule_mass(has_it)
|
||||
|
||||
subroutine ezfio_set_molecule_coord(coord)
|
||||
subroutine ezfio_get_molecule_coord(coord)
|
||||
subroutine ezfio_has_molecule_coord(has_it)
|
||||
|
||||
subroutine ezfio_get_properties_mass(mass)
|
||||
|
||||
subroutine ezfio_set_properties_center_of_mass(center_of_mass)
|
||||
subroutine ezfio_get_properties_center_of_mass(center_of_mass)
|
||||
subroutine ezfio_has_properties_center_of_mass(has_it)
|
||||
|
||||
subroutine ezfio_set_properties_center_of_charge(center_of_charge)
|
||||
subroutine ezfio_get_properties_center_of_charge(center_of_charge)
|
||||
subroutine ezfio_has_properties_center_of_charge(has_it)
|
||||
|
||||
Note that ``ezfio_get_properties_mass`` has only the ``get`` subroutine
|
||||
since it is computed data.
|
||||
|
||||
In Python
|
||||
---------
|
||||
|
||||
All the subroutines are also produced for Python in the ezfio.py file in
|
||||
the Python directory. To use them, in your Python script, use:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
import sys
|
||||
EZFIO = "./EZFIO" # Put here the absolute path to the EZFIO directory
|
||||
sys.path = [ EZFIO+"/Python" ]+sys.path
|
||||
from ezfio import ezfio
|
||||
|
||||
and all the subroutines will be accessible by replacing the first
|
||||
underscore character of the name of the subroutine by a dot (``ezfio_``
|
||||
becomes ``ezfio.``).
|
||||
|
||||
Let us create the input of our Fortran program with a Python script.
|
||||
Create a file named ``create_input.py`` with:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
#!/usr/bin/python
|
||||
|
||||
import sys
|
||||
EZFIO = "./EZFIO" # Put here the absolute path to the EZFIO directory
|
||||
sys.path = [ EZFIO+"/Python" ]+sys.path
|
||||
from ezfio import ezfio
|
||||
|
||||
# Water molecule:
|
||||
# mass, x, y, z
|
||||
input = """16. 0.000000 0.222396 0.000000
|
||||
1. 1.436494 -0.889660 0.000000
|
||||
1. -1.436494 -0.889660 0.000000 """
|
||||
|
||||
Molecule = []
|
||||
for line in input.splitlines():
|
||||
new_list = map(eval,line.split())
|
||||
Molecule.append(new_list)
|
||||
|
||||
# Create the mass array
|
||||
mass = map( lambda x: x[0], Molecule )
|
||||
# print mass
|
||||
# [16.0, 1.0, 1.0]
|
||||
|
||||
# Create the coord array
|
||||
coord = map( lambda x: (x[1], x[2], x[3]), Molecule )
|
||||
# print coord
|
||||
# [(0.0, 0.222396, 0.0), (1.436494, -0.88966, 0.0), (-1.436494, -0.88966, 0.0)]
|
||||
|
||||
# Select the EZFIO file
|
||||
ezfio.set_file("Water")
|
||||
|
||||
# Add the arrays to the file
|
||||
ezfio.molecule_num_atoms = len(Molecule)
|
||||
ezfio.molecule_mass = mass
|
||||
ezfio.molecule_coord = coord
|
||||
|
||||
# Check that the total charge and mass is correct:
|
||||
print ezfio.properties_mass # Should give 18.
|
||||
|
||||
Execute the script:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ python create_input.py
|
||||
18.0
|
||||
|
||||
The printed mass is correct, and a new directory (``Water``) was created with our data:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ ls Water/*
|
||||
Water/ezfio:
|
||||
creation
|
||||
|
||||
Water/molecule:
|
||||
charge.gz coord.gz mass.gz num_atoms
|
||||
|
||||
In Fortran
|
||||
----------
|
||||
|
||||
We will create here a Fortran program which reads the atomic coordinates
|
||||
and the atomic masses from an EZFIO file, computes the coordinates of
|
||||
the center of mass, and writes the coordinates of the center of mass to
|
||||
the EZFIO file.
|
||||
|
||||
.. code-block:: fortran
|
||||
|
||||
program test
|
||||
implicit none
|
||||
integer :: num_atoms
|
||||
real, allocatable :: mass(:)
|
||||
real, allocatable :: coord(:,:)
|
||||
real :: center_of_mass(3)
|
||||
real :: total_mass
|
||||
integer :: i,j
|
||||
|
||||
! Set which file is read/written
|
||||
call ezfio_set_file("Water")
|
||||
|
||||
! Read the number of atoms
|
||||
call ezfio_get_molecule_num_atoms(num_atoms)
|
||||
|
||||
! Allocate the mass and coord arrays
|
||||
allocate(mass(num_atoms), coord(3,num_atoms))
|
||||
|
||||
! Read the arrays from the file
|
||||
call ezfio_get_molecule_mass(mass)
|
||||
call ezfio_get_molecule_coord(coord)
|
||||
|
||||
! Check that the read data is correct
|
||||
print *, 'Data in the EZFIO file:'
|
||||
do i=1,num_atoms
|
||||
print *, mass(i), (coord(j,i),j=1,3)
|
||||
end do
|
||||
! prints:
|
||||
! Data in the EZFIO file:
|
||||
! 16.00000 0.000000 0.2223960 0.000000
|
||||
! 1.000000 1.436494 -0.8896600 0.000000
|
||||
! 1.000000 -1.436494 -0.8896600 0.000000
|
||||
|
||||
! Perform the calculation of the center of mass
|
||||
do j=1,3
|
||||
center_of_mass(j) = 0.
|
||||
end do
|
||||
|
||||
do i=1,num_atoms
|
||||
do j=1,3
|
||||
center_of_mass(j) = center_of_mass(j) + mass(i)*coord(j,i)
|
||||
end do
|
||||
end do
|
||||
|
||||
call ezfio_get_properties_mass(total_mass)
|
||||
do j=1,3
|
||||
center_of_mass(j) = center_of_mass(j)/total_mass
|
||||
end do
|
||||
|
||||
deallocate(mass, coord)
|
||||
|
||||
! Write the center of mass to the EZFIO file
|
||||
call ezfio_set_properties_center_of_mass(center_of_mass)
|
||||
|
||||
end
|
||||
|
||||
A new directory (``properties``) was created with the center_of_mass
|
||||
file:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ ls Water/*
|
||||
Water/ezfio:
|
||||
creation
|
||||
|
||||
Water/molecule:
|
||||
charge.gz coord.gz mass.gz num_atoms
|
||||
|
||||
Water/properties:
|
||||
center_of_mass.gz
|
||||
|
||||
|
||||
Compile and run the program using:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ $FC -o test test.F90 EZFIO/lib/libezfio.a
|
||||
$ ./test
|
||||
|
||||
where ``$FC`` is your fortran compiler, and ``test.F90`` is the file
|
||||
containing the test example. If you don't have the EZFIO static
|
||||
library, you can use the shared library as:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD/EZFIO/lib
|
||||
$ $FC -o test -L./EZFIO/lib -lezfio
|
||||
|
0
config/.empty
Normal file
0
config/.empty
Normal file
5
config/ezfio.config
Normal file
5
config/ezfio.config
Normal file
@ -0,0 +1,5 @@
|
||||
ezfio
|
||||
creation character*(64)
|
||||
user character*(64)
|
||||
library character*(2048)
|
||||
last_library character*(2048)
|
134
configure.ac
Normal file
134
configure.ac
Normal file
@ -0,0 +1,134 @@
|
||||
# EZFIO is an automatic generator of I/O libraries
|
||||
# Copyright (C) 2009 Anthony SCEMAMA, CNRS
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Anthony Scemama
|
||||
# LCPQ - IRSAMC - CNRS
|
||||
# Universite Paul Sabatier
|
||||
# 118, route de Narbonne
|
||||
# 31062 Toulouse Cedex 4
|
||||
# scemama@irsamc.ups-tlse.fr
|
||||
# -*- Autoconf -*-
|
||||
# Process this file with autoconf to produce a configure script.
|
||||
|
||||
VERSION=[`. version ; echo $VERSION`]
|
||||
AC_SUBST([VERSION])
|
||||
|
||||
AC_REVISION([$Revision: $VERSION $])
|
||||
|
||||
AC_PREREQ([2.50])
|
||||
|
||||
AC_INIT([EZFIO Library Generator], [], [scemama@irsamc.ups-tlse.fr],[ezfio],[http://ezfio.sourceforge.net])
|
||||
|
||||
AC_SYS_LONG_FILE_NAMES
|
||||
ROOT=`pwd`
|
||||
AC_SUBST([ROOT])
|
||||
|
||||
AC_CONFIG_SRCDIR([src/run.irp.f])
|
||||
AC_CONFIG_FILES([make.config])
|
||||
AC_PREFIX_DEFAULT([./])
|
||||
|
||||
STATIC_LIB=$ROOT/lib/libezfio.a
|
||||
|
||||
AC_PROG_RANLIB
|
||||
|
||||
# Test Fortran
|
||||
# ------------
|
||||
|
||||
AC_LANG([Fortran])
|
||||
AC_PROG_FC([ifort gfortran],[Fortran 90])
|
||||
AC_PROG_FC_C_O
|
||||
AC_FC_SRCEXT([F90])
|
||||
AC_FC_FREEFORM
|
||||
|
||||
# Test Python
|
||||
# ------------
|
||||
|
||||
AC_CHECK_PROG([PYTHON],[python],[yes],[no])
|
||||
if [[ "$PYTHON" = no ]] ; then
|
||||
AC_MSG_ERROR([Please install Python.])
|
||||
fi
|
||||
|
||||
# Test AR
|
||||
# -------
|
||||
|
||||
if [[ -z "$AR" ]] ; then
|
||||
AC_CHECK_PROG([AR],[ar],[yes],[no])
|
||||
if [[ "$AR" = no ]] ; then
|
||||
AC_MSG_ERROR([ar not found.])
|
||||
fi
|
||||
AR=ar
|
||||
fi
|
||||
AC_SUBST([AR])
|
||||
|
||||
# Test Gzip and zcat
|
||||
# ------------------
|
||||
|
||||
if [[ -z "$HAS_GZIP" ]] ; then
|
||||
AC_CHECK_PROG([GZIP],[gzip],[yes],[no])
|
||||
if [[ "$GZIP" = no ]] ; then
|
||||
HAS_GZIP="-DNO_GZIP"
|
||||
fi
|
||||
|
||||
AC_CHECK_PROG([ZCAT],[zcat],[yes],[no])
|
||||
if [[ "$ZCAT" = no ]] ; then
|
||||
HAS_GZIP="-DNO_GZIP"
|
||||
fi
|
||||
|
||||
AC_CHECK_PROG([MKFIFO],[mkfifo],[yes],[no])
|
||||
if [[ "$MKFIFO" = no ]] ; then
|
||||
HAS_GZIP="-DNO_GZIP"
|
||||
fi
|
||||
fi
|
||||
AC_SUBST([HAS_GZIP])
|
||||
|
||||
# Test IRPF90
|
||||
# ------------
|
||||
|
||||
if [[ -z "$IRPF90" ]] ; then
|
||||
AC_CHECK_PROG([IRPF90],[irpf90],[yes],[no])
|
||||
if [[ "$IRPF90" = no ]] ; then
|
||||
AC_MSG_ERROR([Please install IRPF90:\nhttp://irpf90.ups-tlse.fr])
|
||||
fi
|
||||
IRPF90=`which irpf90`
|
||||
fi
|
||||
AC_SUBST([IRPF90])
|
||||
|
||||
if [[ -z "$FCFLAGS" ]] ; then
|
||||
case $FC in
|
||||
ifort*)
|
||||
FCFLAGS="-O2 -g -ip"
|
||||
STATIC_FC="-static-intel -static-libgcc -static"
|
||||
;;
|
||||
gfortran*)
|
||||
FCFLAGS="-O2 -g -ffree-line-length-none"
|
||||
STATIC_FC="-static-libgcc -static"
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Write make.config
|
||||
|
||||
LIB="$STATIC_LIB"
|
||||
FCFLAGS="$FCFLAGS $STATIC_FC"
|
||||
AC_SUBST([LIB])
|
||||
|
||||
# Done
|
||||
#-----
|
||||
|
||||
AC_OUTPUT
|
||||
|
||||
|
13
git-tools/commit-msg
Executable file
13
git-tools/commit-msg
Executable file
@ -0,0 +1,13 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import os,sys
|
||||
ROOT = os.path.dirname(__file__)+'/../../'
|
||||
file = open(ROOT+'version','r')
|
||||
lines = file.readlines()
|
||||
file.close()
|
||||
file = open(sys.argv[1],'a')
|
||||
print >>file, 'Version:'+lines[0].split('=')[1]
|
||||
file.close()
|
||||
|
||||
|
||||
|
10
git-tools/install_tools.sh
Executable file
10
git-tools/install_tools.sh
Executable file
@ -0,0 +1,10 @@
|
||||
#!/bin/bash
|
||||
|
||||
OLD_DIR=$PWD
|
||||
cd ../.git/hooks/
|
||||
|
||||
for i in commit-msg post-commit
|
||||
do
|
||||
rm $i
|
||||
ln -s $OLD_DIR/$i $PWD/$i
|
||||
done
|
17
git-tools/post-commit
Executable file
17
git-tools/post-commit
Executable file
@ -0,0 +1,17 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import os
|
||||
ROOT = os.path.dirname(__file__)+'/../../'
|
||||
|
||||
file = open(ROOT+'version','r') ;
|
||||
lines = file.readlines() ;
|
||||
file.close() ;
|
||||
v = map(int,lines[0].split('=')[1].split('.'));
|
||||
|
||||
v[2] += 1
|
||||
lines[0] = "VERSION=%d.%d.%d\n"%tuple(v)
|
||||
|
||||
file = open(ROOT+'version','w')
|
||||
file.writelines(lines)
|
||||
file.close()
|
||||
|
0
lib/.empty
Normal file
0
lib/.empty
Normal file
5
make.config.in
Normal file
5
make.config.in
Normal file
@ -0,0 +1,5 @@
|
||||
IRPF90 = @IRPF90@ @HAS_GZIP@
|
||||
FC = @FC@ -fPIC
|
||||
FCFLAGS= @FCFLAGS@
|
||||
RANLIB = @RANLIB@
|
||||
AR = @AR@
|
59
src/Makefile
Normal file
59
src/Makefile
Normal file
@ -0,0 +1,59 @@
|
||||
# EZFIO is an automatic generator of I/O libraries
|
||||
# Copyright (C) 2009 Anthony SCEMAMA, CNRS
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Anthony Scemama
|
||||
# LCPQ - IRSAMC - CNRS
|
||||
# Universite Paul Sabatier
|
||||
# 118, route de Narbonne
|
||||
# 31062 Toulouse Cedex 4
|
||||
# scemama@irsamc.ups-tlse.fr
|
||||
|
||||
DEFAULT_TARGET: python
|
||||
|
||||
../make.config:
|
||||
make -C .. make.config
|
||||
include ../make.config
|
||||
|
||||
include irpf90.make
|
||||
|
||||
irpf90.make: $(wildcard *.irp.f) ../config/*
|
||||
$(IRPF90)
|
||||
|
||||
include ../version
|
||||
|
||||
.PHONY: python static
|
||||
|
||||
static: ../lib/libezfio_irp.a ../lib/libezfio.a
|
||||
|
||||
../lib/libezfio.a: $(OBJ1)
|
||||
- bash -c "[[ -e ../libezfio.a ]] && rm ../lib/libezfio.a"
|
||||
$(AR) cru ../lib/libezfio.a $(OBJ1)
|
||||
$(RANLIB) ../lib/libezfio.a
|
||||
|
||||
../lib/libezfio_irp.a: ../lib/libezfio.a
|
||||
cp ../lib/libezfio.a ../lib/libezfio_irp.a
|
||||
$(AR) dv ../lib/libezfio_irp.a irp_stack.irp.o
|
||||
$(RANLIB) ../lib/libezfio_irp.a
|
||||
|
||||
test: static
|
||||
ifort -o $@ IRPF90_temp/run.irp.F90 -L../lib/ -lezfio
|
||||
|
||||
python: static
|
||||
cat ezfio-head.py libezfio_groups-gen.py libezfio_util-gen.py ezfio-tail.py > ../Python/ezfio.py
|
||||
|
||||
ezfio.py: python
|
||||
|
89
src/create_ocaml.py
Executable file
89
src/create_ocaml.py
Executable file
@ -0,0 +1,89 @@
|
||||
#!/usr/bin/env python
|
||||
# EZFIO is an automatic generator of I/O libraries
|
||||
# Copyright (C) 2009 Anthony SCEMAMA, CNRS
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Anthony Scemama
|
||||
# LCPQ - IRSAMC - CNRS
|
||||
# Universite Paul Sabatier
|
||||
# 118, route de Narbonne
|
||||
# 31062 Toulouse Cedex 4
|
||||
# scemama@irsamc.ups-tlse.fr
|
||||
|
||||
import re
|
||||
from read_config import groups
|
||||
from groups_templates import *
|
||||
from f_types import t_short, f2ocaml
|
||||
import os
|
||||
|
||||
import sys
|
||||
|
||||
def run():
|
||||
|
||||
head = []
|
||||
tail = []
|
||||
|
||||
file = open("../version","r")
|
||||
v = file.readline()
|
||||
file.close()
|
||||
v = v.split('=')[1].strip()
|
||||
l = os.getcwd().replace('/src','')
|
||||
head += ["""let version = "%s";;"""%(v),
|
||||
"""let library = "%s";;"""%(l)]
|
||||
|
||||
for group in groups.keys():
|
||||
for var,type,dims,command in groups[group]:
|
||||
if command is not "":
|
||||
continue
|
||||
dims_py = str(dims)
|
||||
for g in groups.keys():
|
||||
dims_py = dims_py.replace(g,'self.'+g)
|
||||
var = var.lower()
|
||||
group = group.lower()
|
||||
strdims = tuple(map(lambda x: '('+str(x)+')',dims))
|
||||
strdims = str(strdims).replace("'","")
|
||||
if len(dims) == 1:
|
||||
strdims = strdims[:-2]+")"
|
||||
dim_max = strdims[1:-1].replace(',','*')
|
||||
type_set = type
|
||||
if type.lower().startswith('character'):
|
||||
type_set = 'character*(*)'
|
||||
d = { 'type_short': f2ocaml[t_short(type)],
|
||||
'type': type,
|
||||
'type_set': type_set,
|
||||
'var': var,
|
||||
'group': group,
|
||||
'dims': strdims}
|
||||
if dims == ():
|
||||
tail += ['let get_%(group)s_%(var)s () = read_%(type_short)s "%(group)s" "%(var)s";;' %(d),
|
||||
'let set_%(group)s_%(var)s = write_%(type_short)s "%(group)s" "%(var)s" ;;' %(d) ,
|
||||
'let has_%(group)s_%(var)s () = has "%(group)s" "%(var)s" ;;' %(d) ]
|
||||
else:
|
||||
tail += ['let get_%(group)s_%(var)s () = read_%(type_short)s_array "%(group)s" "%(var)s";;' %(d),
|
||||
'let set_%(group)s_%(var)s = write_%(type_short)s_array "%(group)s" "%(var)s";;' %(d) ,
|
||||
'let has_%(group)s_%(var)s () = has_array "%(group)s" "%(var)s" ;;' %(d) ]
|
||||
|
||||
|
||||
file = open('ezfio.ml','r')
|
||||
template = file.read()
|
||||
file.close()
|
||||
template = template.replace("(*$HEAD*)",'\n'.join(head))
|
||||
template = template.replace("(*$TAIL*)",'\n'.join(tail))
|
||||
|
||||
file = open('../Ocaml/ezfio.ml','w')
|
||||
file.write(template)
|
||||
file.close()
|
||||
|
256
src/ezfio-head.py
Normal file
256
src/ezfio-head.py
Normal file
@ -0,0 +1,256 @@
|
||||
# EZFIO is an automatic generator of I/O libraries
|
||||
# Copyright (C) 2009 Anthony SCEMAMA, CNRS
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Anthony Scemama
|
||||
# LCPQ - IRSAMC - CNRS
|
||||
# Universite Paul Sabatier
|
||||
# 118, route de Narbonne
|
||||
# 31062 Toulouse Cedex 4
|
||||
# scemama@irsamc.ups-tlse.fr
|
||||
|
||||
import os, sys
|
||||
import time
|
||||
import cStringIO as StringIO
|
||||
from gzip import GzipFile
|
||||
import tempfile
|
||||
import threading
|
||||
|
||||
def version(x):
|
||||
b = [int(i) for i in x.split('.')]
|
||||
return b[2] + b[1]*100 + b[0]*10000
|
||||
|
||||
def size(x):
|
||||
return len(x)
|
||||
|
||||
def flatten(l):
|
||||
res = []
|
||||
for i in l:
|
||||
if hasattr(i, "__iter__") and not isinstance(i, basestring):
|
||||
res.extend(flatten(i))
|
||||
else:
|
||||
res.append(i)
|
||||
return res
|
||||
|
||||
def maxval(l):
|
||||
return reduce(max, l, l[0])
|
||||
|
||||
def minval(l):
|
||||
return reduce(min, l, l[0])
|
||||
|
||||
|
||||
def reshape(l,shape):
|
||||
l = flatten(l)
|
||||
for d in shape[:-1]:
|
||||
buffer = []
|
||||
buffer2 = []
|
||||
i=0
|
||||
while i<len(l):
|
||||
buffer2.append(l[i])
|
||||
if len(buffer2) == d:
|
||||
buffer.append(buffer2)
|
||||
buffer2 = []
|
||||
i+=1
|
||||
l = list(buffer)
|
||||
return l
|
||||
|
||||
def at(array,index):
|
||||
return array[index-1]
|
||||
|
||||
def n_count_ch(array,isize,val):
|
||||
result = 0
|
||||
for i in array:
|
||||
if i == val:
|
||||
result +=1
|
||||
return result
|
||||
|
||||
n_count_in = n_count_ch
|
||||
n_count_do = n_count_ch
|
||||
n_count_lo = n_count_ch
|
||||
|
||||
|
||||
def get_conv(type):
|
||||
if type in ["do","re"]:
|
||||
conv = float
|
||||
elif type in ["in","i8"]:
|
||||
conv = int
|
||||
elif type == "lo":
|
||||
def conv(a):
|
||||
if a == True:
|
||||
return 'T'
|
||||
elif a == False:
|
||||
return 'F'
|
||||
elif a.lower() == 't':
|
||||
return True
|
||||
elif a.lower() == 'f':
|
||||
return False
|
||||
else:
|
||||
raise TypeError
|
||||
elif type == "ch":
|
||||
conv = lambda x: x.strip()
|
||||
else:
|
||||
raise TypeError
|
||||
return conv
|
||||
|
||||
class ezfio_obj(object):
|
||||
|
||||
def __init__(self,read_only=False):
|
||||
self._filename = "EZFIO_File"
|
||||
self.buffer_rank = -1
|
||||
self.read_only = read_only
|
||||
self.locks = {}
|
||||
|
||||
def acquire_lock(self,var):
|
||||
locks = self.locks
|
||||
try:
|
||||
locks[var].acquire()
|
||||
except:
|
||||
locks[var] = threading.Lock()
|
||||
locks[var].acquire()
|
||||
|
||||
def release_lock(self,var):
|
||||
self.locks[var].release()
|
||||
|
||||
def set_read_only(self,v):
|
||||
self.read_only = v
|
||||
|
||||
def get_read_only(self):
|
||||
return self.read_only
|
||||
|
||||
def exists(self,path):
|
||||
if os.access(path+'/.version',os.F_OK) == 1:
|
||||
file = open(path+'/.version',"r")
|
||||
v = file.readline().strip()
|
||||
file.close()
|
||||
else:
|
||||
return False
|
||||
|
||||
def mkdir(self,path):
|
||||
if self.read_only:
|
||||
self.error('Read-only file.')
|
||||
if self.exists(path):
|
||||
self.error('mkdir','Group '+path+' exists')
|
||||
try:
|
||||
os.mkdir(path.strip())
|
||||
except OSError:
|
||||
pass
|
||||
file = open(path.strip()+'/.version','w')
|
||||
print >>file,self.version
|
||||
file.close()
|
||||
|
||||
def error(self,where,txt):
|
||||
print '------------------------------------------------------------'
|
||||
print 'EZFIO File : '+self.filename
|
||||
print 'EZFIO Error in : '+where.strip()
|
||||
print '------------------------------------------------------------'
|
||||
print ''
|
||||
print txt.strip()
|
||||
print ''
|
||||
print '------------------------------------------------------------'
|
||||
raise IOError
|
||||
|
||||
def get_filename(self):
|
||||
if not self.exists(self._filename):
|
||||
self.mkdir(self._filename)
|
||||
return self._filename
|
||||
|
||||
def set_filename(self,filename):
|
||||
self._filename = filename
|
||||
|
||||
filename = property(fset=set_filename,fget=get_filename)
|
||||
|
||||
def set_file(self,filename):
|
||||
self.filename = filename
|
||||
if not self.exists(filename):
|
||||
self.mkdir(filename)
|
||||
self.mkdir(filename+"/ezfio")
|
||||
os.system("""
|
||||
LANG= date > %s/ezfio/creation
|
||||
echo $USER > %s/ezfio/user
|
||||
echo %s > %s/ezfio/library"""%(filename,filename,self.LIBRARY,filename))
|
||||
|
||||
def open_write_buffer(self,dir,fil,rank):
|
||||
if self.read_only:
|
||||
self.error('Read-only file.')
|
||||
l_filename=dir.strip()+'/'+fil+'.gz'
|
||||
if self.buffer_rank != -1:
|
||||
self.error('open_write_buffer','Another buffered file is already open.')
|
||||
|
||||
self.buffer_rank = rank
|
||||
assert (self.buffer_rank > 0)
|
||||
|
||||
try:
|
||||
self.file = GzipFile(filename=l_filename,mode='wb7')
|
||||
except IOError:
|
||||
self.error('open_write_buffer','Unable to open buffered file.')
|
||||
|
||||
self.file.write("%2d\n"%(rank,))
|
||||
|
||||
|
||||
def open_read_buffer(self,dir,fil,rank):
|
||||
l_filename=dir.strip()+'/'+fil+'.gz'
|
||||
|
||||
if self.buffer_rank != -1:
|
||||
self.error('open_read_buffer','Another buffered file is already open.')
|
||||
|
||||
try:
|
||||
self.file = GzipFile(filename=l_filename,mode='rb')
|
||||
except IOError:
|
||||
self.error('open_read_buffer','Unable to open buffered file.')
|
||||
|
||||
try:
|
||||
rank = eval(self.file.readline())
|
||||
except IOError:
|
||||
self.error('open_read_buffer','Unable to read buffered file.')
|
||||
|
||||
self.buffer_rank = rank
|
||||
assert (self.buffer_rank > 0)
|
||||
return rank
|
||||
|
||||
def close_buffer(self):
|
||||
assert (self.buffer_rank > 0)
|
||||
self.buffer_rank = -1
|
||||
self.file.close()
|
||||
|
||||
def read_buffer(self,isize):
|
||||
|
||||
if self.buffer_rank == -1:
|
||||
self.error('read_buffer','No buffered file is open.')
|
||||
|
||||
indices = []
|
||||
values = []
|
||||
for i in xrange(isize):
|
||||
try:
|
||||
line = self.file.readline().split()
|
||||
except:
|
||||
return indices, values
|
||||
if len(line) == 0:
|
||||
return indices, values
|
||||
indices.append ( [ int(i) for i in line[:-1] ] )
|
||||
values.append (eval(line[-1]))
|
||||
return indices, values
|
||||
|
||||
def write_buffer(self,indices,values,isize):
|
||||
if self.read_only:
|
||||
self.error('Read-only file.')
|
||||
if self.buffer_rank == -1:
|
||||
self.error('write_buffer','No buffered file is open.')
|
||||
|
||||
for i in xrange(isize):
|
||||
for j in indices[i]:
|
||||
self.file.write("%4d "%(j,))
|
||||
self.file.write("%24.15e\n"%(values[i],))
|
||||
|
26
src/ezfio-tail.py
Normal file
26
src/ezfio-tail.py
Normal file
@ -0,0 +1,26 @@
|
||||
# EZFIO is an automatic generator of I/O libraries
|
||||
# Copyright (C) 2009 Anthony SCEMAMA, CNRS
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Anthony Scemama
|
||||
# LCPQ - IRSAMC - CNRS
|
||||
# Universite Paul Sabatier
|
||||
# 118, route de Narbonne
|
||||
# 31062 Toulouse Cedex 4
|
||||
# scemama@irsamc.ups-tlse.fr
|
||||
|
||||
ezfio = ezfio_obj()
|
||||
|
421
src/ezfio.ml
Normal file
421
src/ezfio.ml
Normal file
@ -0,0 +1,421 @@
|
||||
(*
|
||||
EZFIO is an automatic generator of I/O libraries
|
||||
Copyright (C) 2009 Anthony SCEMAMA, CNRS
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Anthony Scemama
|
||||
LCPQ - IRSAMC - CNRS
|
||||
Universite Paul Sabatier
|
||||
118, route de Narbonne
|
||||
31062 Toulouse Cedex 4
|
||||
scemama@irsamc.ups-tlse.fr
|
||||
*)
|
||||
|
||||
(*$HEAD*)
|
||||
|
||||
(*
|
||||
Exceptions
|
||||
==========
|
||||
*)
|
||||
|
||||
exception Read_only of string;;
|
||||
|
||||
(*
|
||||
State variables
|
||||
===============
|
||||
*)
|
||||
let read_only = ref false;;
|
||||
let ezfio_filename = ref "EZFIO_File";;
|
||||
|
||||
(*
|
||||
Helper functions
|
||||
=================
|
||||
*)
|
||||
|
||||
let check_readonly =
|
||||
if !read_only then
|
||||
raise (Read_only "Read only attribute is set");
|
||||
;;
|
||||
|
||||
let exists path =
|
||||
let filename = path^"/.version" in
|
||||
Sys.file_exists filename
|
||||
;;
|
||||
|
||||
let has group name =
|
||||
let dirname = !ezfio_filename ^ "/" ^ group in
|
||||
if (exists dirname) then
|
||||
(Sys.file_exists (dirname ^ "/" ^ name) )
|
||||
else
|
||||
false
|
||||
;;
|
||||
|
||||
let has_array group name = has group (name^".gz");;
|
||||
|
||||
let mkdir path =
|
||||
check_readonly;
|
||||
if (exists path) then
|
||||
raise (Failure (path^" already exists"));
|
||||
Unix.mkdir path 0o777;
|
||||
let out_channel = open_out (path^"/.version") in
|
||||
Printf.fprintf out_channel "%s\n" version ;
|
||||
close_out out_channel;
|
||||
;;
|
||||
|
||||
let create_group group =
|
||||
let dirname = !ezfio_filename ^ "/" ^ group in
|
||||
if not (exists dirname) then
|
||||
mkdir dirname;
|
||||
;;
|
||||
|
||||
let split line s =
|
||||
let rec do_work lst word = function
|
||||
| 0 -> word::lst
|
||||
| i ->
|
||||
begin
|
||||
match line.[i-1] with
|
||||
| a when a == s ->
|
||||
if word <> "" then
|
||||
do_work (word::lst) "" (i-1)
|
||||
else
|
||||
do_work lst "" (i-1)
|
||||
| a -> do_work lst ( (Char.escaped a)^word) (i-1)
|
||||
end
|
||||
in do_work [] "" (String.length line)
|
||||
;;
|
||||
|
||||
let ltrim s =
|
||||
let rec do_work s l =
|
||||
match s.[0] with
|
||||
| '\n'
|
||||
| ' ' -> do_work (String.sub s 1 (l-1)) (l-1)
|
||||
| _ -> s
|
||||
in
|
||||
do_work s (String.length s)
|
||||
;;
|
||||
|
||||
let rtrim s =
|
||||
let rec do_work s l =
|
||||
let newl = l-1 in
|
||||
match s.[newl] with
|
||||
| '\n'
|
||||
| ' ' -> do_work (String.sub s 0 (newl)) (newl)
|
||||
| _ -> s
|
||||
in
|
||||
do_work s (String.length s)
|
||||
;;
|
||||
|
||||
let trim s = ltrim (rtrim s) ;;
|
||||
|
||||
let maxval l =
|
||||
match l with
|
||||
| [] -> None
|
||||
| [a] -> Some a
|
||||
| hd::tail -> Some (List.fold_left max hd tail)
|
||||
;;
|
||||
|
||||
let minval l =
|
||||
match l with
|
||||
| [] -> None
|
||||
| [a] -> Some a
|
||||
| hd::tail -> Some (List.fold_left min hd tail)
|
||||
;;
|
||||
|
||||
let at arr idx = arr.(idx);;
|
||||
|
||||
let size (_) = 0;;
|
||||
|
||||
let n_count_ch (str,_,v) =
|
||||
let rec do_work accu = function
|
||||
| 0 -> accu
|
||||
| i ->
|
||||
let newaccu =
|
||||
if str.[i-1] == v then accu+1
|
||||
else accu
|
||||
in do_work newaccu (i-1)
|
||||
in do_work 0 (String.length str)
|
||||
;;
|
||||
|
||||
let n_count (l,_,v) =
|
||||
let rec do_work accu = function
|
||||
| [] -> accu
|
||||
| h::tail ->
|
||||
let newaccu =
|
||||
if h == v then accu+1
|
||||
else accu
|
||||
in do_work newaccu tail
|
||||
in do_work 0 l
|
||||
;;
|
||||
|
||||
(*
|
||||
Scalars
|
||||
=======
|
||||
*)
|
||||
|
||||
(*
|
||||
Read
|
||||
----
|
||||
*)
|
||||
|
||||
let read_scalar type_conversion group name =
|
||||
let in_filename = !ezfio_filename ^ "/" ^ group ^ "/" ^ name in
|
||||
let in_channel = open_in in_filename in
|
||||
let trimmed_line = trim (input_line in_channel) in
|
||||
let result = type_conversion trimmed_line in
|
||||
begin
|
||||
close_in in_channel ;
|
||||
result
|
||||
end
|
||||
;;
|
||||
|
||||
let fortran_bool_of_string = function
|
||||
| "T" | "t" -> true
|
||||
| "F" | "f" -> false
|
||||
| x -> raise (Failure ("fortran_bool_of_string should be T or F: "^x))
|
||||
;;
|
||||
|
||||
let fortran_string_of_bool = function
|
||||
| true -> "T\n"
|
||||
| false-> "F\n"
|
||||
;;
|
||||
|
||||
let read_int = read_scalar int_of_string ;;
|
||||
let read_float = read_scalar float_of_string ;;
|
||||
let read_string= read_scalar (fun (x:string) -> x);;
|
||||
let read_bool = read_scalar fortran_bool_of_string;;
|
||||
|
||||
(*
|
||||
Write
|
||||
-----
|
||||
*)
|
||||
|
||||
let print_int out_channel i = Printf.fprintf out_channel "%16d\n" i
|
||||
and print_float out_channel f = Printf.fprintf out_channel "%24.15e\n" f
|
||||
and print_string out_channel s = Printf.fprintf out_channel "%s\n" s
|
||||
and print_bool out_channel b = Printf.fprintf out_channel "%s\n" (fortran_string_of_bool b);;
|
||||
|
||||
let write_scalar print_fun group name s =
|
||||
check_readonly;
|
||||
create_group group;
|
||||
let out_filename = !ezfio_filename ^ "/" ^ group ^ "/" ^ name in
|
||||
let out_channel = open_out out_filename in
|
||||
begin
|
||||
print_fun out_channel s;
|
||||
close_out out_channel;
|
||||
end
|
||||
;;
|
||||
|
||||
let write_int = write_scalar print_int
|
||||
and write_float = write_scalar print_float
|
||||
and write_bool = write_scalar print_bool
|
||||
and write_string = write_scalar print_string
|
||||
;;
|
||||
|
||||
|
||||
|
||||
(*
|
||||
Arrays
|
||||
======
|
||||
*)
|
||||
|
||||
type 'a ezfio_data =
|
||||
| Ezfio_item of 'a array
|
||||
| Ezfio_data of ('a ezfio_data) array
|
||||
;;
|
||||
|
||||
|
||||
type 'a ezfio_array =
|
||||
{ rank : int ;
|
||||
dim : int array;
|
||||
data : 'a ezfio_data ;
|
||||
}
|
||||
;;
|
||||
|
||||
let ezfio_get_element { rank=r ; dim=d ; data=data } coord =
|
||||
(*assert ((List.length coord) == r);*)
|
||||
let rec do_work buffer = function
|
||||
| [c] ->
|
||||
begin match buffer with
|
||||
| Ezfio_item buffer -> buffer.(c)
|
||||
| Ezfio_data buffer -> raise (Failure "Error in ezfio_get_element")
|
||||
end
|
||||
| c::tail ->
|
||||
begin match buffer with
|
||||
| Ezfio_item buffer -> raise (Failure "Error in ezfio_get_element")
|
||||
| Ezfio_data buffer -> do_work buffer.(c) tail
|
||||
end
|
||||
| [] -> raise (Failure "Error in ezfio_get_element")
|
||||
in
|
||||
do_work data coord
|
||||
;;
|
||||
|
||||
|
||||
let flattened_ezfio_data d =
|
||||
match d with
|
||||
| Ezfio_item d -> d
|
||||
| Ezfio_data d ->
|
||||
let d = Array.to_list d in
|
||||
let rec do_work accu = function
|
||||
| [] -> accu
|
||||
| (Ezfio_item x)::tail -> do_work (Array.append accu x) tail
|
||||
| (Ezfio_data x)::tail ->
|
||||
let newaccu = do_work accu (Array.to_list x )
|
||||
in do_work newaccu tail
|
||||
in
|
||||
do_work (Array.of_list []) d
|
||||
;;
|
||||
|
||||
|
||||
(*
|
||||
Read
|
||||
----
|
||||
*)
|
||||
|
||||
let unzipped_filename filename =
|
||||
if not (Sys.file_exists filename) then
|
||||
raise (Failure ("file "^filename^" doesn't exist"));
|
||||
let uz_filename = Filename.temp_file "" ".tmp" ~temp_dir:(Sys.getcwd ()) in
|
||||
let command = "zcat "^filename^" > "^uz_filename
|
||||
in
|
||||
if (Sys.command command) == 0 then
|
||||
uz_filename
|
||||
else
|
||||
begin
|
||||
Sys.remove uz_filename ;
|
||||
raise (Failure ("Unable to execute :\n"^command))
|
||||
end
|
||||
;;
|
||||
|
||||
let read_rank in_channel =
|
||||
let trimmed_line = trim (input_line in_channel) in
|
||||
int_of_string trimmed_line
|
||||
;;
|
||||
|
||||
let read_dimensions in_channel =
|
||||
let trimmed_line = trim (input_line in_channel) in
|
||||
let list_of_str = split trimmed_line ' ' in
|
||||
Array.of_list (List.map int_of_string list_of_str)
|
||||
;;
|
||||
|
||||
|
||||
let read_array type_conversion group name : 'a ezfio_array =
|
||||
let in_filename = !ezfio_filename ^ "/" ^ group ^ "/" ^ name ^ ".gz" in
|
||||
let uz_filename = unzipped_filename in_filename in
|
||||
let in_channel = open_in uz_filename in
|
||||
(* Read rank *)
|
||||
let rank = read_rank in_channel
|
||||
(* Read dimensions *)
|
||||
and dimensions = read_dimensions in_channel
|
||||
in
|
||||
begin
|
||||
assert (rank == Array.length dimensions) ;
|
||||
(* Read one-dimensional arrays *)
|
||||
let read_1d nmax =
|
||||
let rec do_work accu = function
|
||||
| 0 -> Array.of_list (List.rev accu)
|
||||
| n ->
|
||||
let trimmed_line = trim (input_line in_channel) in
|
||||
do_work ( (type_conversion trimmed_line)::accu ) (n-1)
|
||||
in
|
||||
Ezfio_item (do_work [] nmax)
|
||||
in
|
||||
(* Read multi-dimensional arrays *)
|
||||
let rec read_nd = function
|
||||
| m when m<1 -> raise (Failure "dimension should not be <1")
|
||||
| 1 -> read_1d dimensions.(0)
|
||||
| m ->
|
||||
let rec do_work accu = function
|
||||
| 0 -> Array.of_list (List.rev accu)
|
||||
| n ->
|
||||
let newlist = read_nd (m-1) in
|
||||
do_work (newlist::accu) (n-1)
|
||||
in
|
||||
Ezfio_data (do_work [] dimensions.(m-1))
|
||||
in
|
||||
let result = {
|
||||
rank = rank ;
|
||||
dim = dimensions ;
|
||||
data = read_nd rank ;
|
||||
}
|
||||
in
|
||||
close_in in_channel ;
|
||||
Sys.remove uz_filename ;
|
||||
result;
|
||||
end
|
||||
;;
|
||||
|
||||
let read_int_array = read_array int_of_string
|
||||
and read_float_array = read_array float_of_string
|
||||
and read_bool_array = read_array fortran_bool_of_string
|
||||
and read_string_array = read_array (fun (x:string) -> x)
|
||||
;;
|
||||
|
||||
(*
|
||||
Write
|
||||
-----
|
||||
*)
|
||||
|
||||
let write_array print_fun group name a =
|
||||
check_readonly;
|
||||
create_group group;
|
||||
let out_filename = !ezfio_filename ^ "/" ^ group ^ "/" ^ name ^".gz" in
|
||||
let uz_filename = Filename.temp_file "" ".tmp" ~temp_dir:(Sys.getcwd ()) in
|
||||
let out_channel = open_out uz_filename in
|
||||
let { rank=rank ; dim=dimensions ; data=data } = a in
|
||||
let data = flattened_ezfio_data data
|
||||
in
|
||||
begin
|
||||
(* Write rank *)
|
||||
Printf.fprintf out_channel "%4d\n" rank;
|
||||
(* Write dimensions *)
|
||||
Array.iter (Printf.fprintf out_channel " %8d") dimensions;
|
||||
Printf.fprintf out_channel "\n";
|
||||
Array.iter (print_fun out_channel) data;
|
||||
close_out out_channel ;
|
||||
let command = "gzip -c < "^uz_filename^" > "^out_filename
|
||||
in
|
||||
if (Sys.command command == 0) then (Sys.remove uz_filename )
|
||||
else raise (Failure ("command failed:\n"^command))
|
||||
end
|
||||
;;
|
||||
|
||||
let write_int_array = write_array print_int
|
||||
and write_float_array = write_array print_float
|
||||
and write_string_array = write_array print_string
|
||||
and write_bool_array = write_array print_bool;;
|
||||
|
||||
(*
|
||||
Library routines
|
||||
*)
|
||||
|
||||
let set_file filename =
|
||||
if not (exists filename) then
|
||||
begin
|
||||
mkdir filename;
|
||||
mkdir (filename^"/ezfio");
|
||||
let command = Printf.sprintf "
|
||||
LANG= date > %s/ezfio/creation
|
||||
echo $USER > %s/ezfio/user
|
||||
echo %s > %s/ezfio/library" filename filename library filename
|
||||
in
|
||||
if (Sys.command command <> 0) then
|
||||
raise (Failure ("Unable to create new ezfio file:\n"^filename))
|
||||
end ;
|
||||
ezfio_filename := filename
|
||||
;;
|
||||
|
||||
|
||||
(*$TAIL*)
|
65
src/f_types.py
Normal file
65
src/f_types.py
Normal file
@ -0,0 +1,65 @@
|
||||
# EZFIO is an automatic generator of I/O libraries
|
||||
# Copyright (C) 2009 Anthony SCEMAMA, CNRS
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Anthony Scemama
|
||||
# LCPQ - IRSAMC - CNRS
|
||||
# Universite Paul Sabatier
|
||||
# 118, route de Narbonne
|
||||
# 31062 Toulouse Cedex 4
|
||||
# scemama@irsamc.ups-tlse.fr
|
||||
|
||||
format= {
|
||||
'integer*8' : ["'(I20)'", "%20d"],
|
||||
'integer' : ["'(I20)'", "%20d"],
|
||||
'real' : ["'(E24.15)'","%24.15E"],
|
||||
'double precision': ["'(E24.15)'","%24.15E"],
|
||||
'logical' : ["'(L)'","%c"],
|
||||
'character*(*)' : ["'(A)'","%s"]
|
||||
}
|
||||
|
||||
def t_short(x):
|
||||
x = x.lower()
|
||||
if x == 'integer*8':
|
||||
return 'i8'
|
||||
elif x == 'integer':
|
||||
return 'in'
|
||||
elif x == 'real':
|
||||
return 're'
|
||||
elif x.startswith('double'):
|
||||
return 'do'
|
||||
elif x == 'logical':
|
||||
return 'lo'
|
||||
elif x.startswith('character'):
|
||||
return 'ch'
|
||||
|
||||
f2c = {
|
||||
'in' : 'int',
|
||||
're' : 'float',
|
||||
'i8' : 'long int',
|
||||
'do' : 'double',
|
||||
'ch' : 'char',
|
||||
'lo' : 'int'
|
||||
}
|
||||
|
||||
f2ocaml = {
|
||||
'in' : 'int',
|
||||
're' : 'float',
|
||||
'i8' : 'int',
|
||||
'do' : 'float',
|
||||
'ch' : 'string',
|
||||
'lo' : 'bool'
|
||||
}
|
150
src/groups.py
Normal file
150
src/groups.py
Normal file
@ -0,0 +1,150 @@
|
||||
#!/usr/bin/python
|
||||
# EZFIO is an automatic generator of I/O libraries
|
||||
# Copyright (C) 2009 Anthony SCEMAMA, CNRS
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Anthony Scemama
|
||||
# LCPQ - IRSAMC - CNRS
|
||||
# Universite Paul Sabatier
|
||||
# 118, route de Narbonne
|
||||
# 31062 Toulouse Cedex 4
|
||||
# scemama@irsamc.ups-tlse.fr
|
||||
|
||||
|
||||
import re
|
||||
from read_config import groups
|
||||
from groups_templates import *
|
||||
from f_types import t_short, f2c
|
||||
|
||||
file_py = open("libezfio_groups-gen.py","w")
|
||||
file = open("../version","r")
|
||||
v = file.readline()
|
||||
file.close()
|
||||
v = v.split('=')[1].strip()
|
||||
print >>file_py, """
|
||||
def get_version(self):
|
||||
return '%s'
|
||||
version = property(fset=None,fget=get_version)
|
||||
"""%(v)
|
||||
|
||||
import sys
|
||||
|
||||
for group in groups.keys():
|
||||
print path%{ 'group' : group }
|
||||
print >>file_py, path_py%{ 'group' : group }
|
||||
for var,type,dims,command in groups[group]:
|
||||
command_py = command
|
||||
dims_py = str(dims)
|
||||
for g in groups.keys():
|
||||
command_py = command_py.replace(g,'self.'+g)
|
||||
dims_py = dims_py.replace(g,'self.'+g)
|
||||
var = var.lower()
|
||||
group = group.lower()
|
||||
strdims = tuple(map(lambda x: '('+str(x)+')',dims))
|
||||
strdims = str(strdims).replace("'","")
|
||||
if len(dims) == 1:
|
||||
strdims = strdims[:-2]+")"
|
||||
dim_max = strdims[1:-1].replace(',','*')
|
||||
type_set = type
|
||||
cstring = ""
|
||||
cstring2 = ""
|
||||
if type.lower().startswith('character'):
|
||||
type_set = 'character*(*)'
|
||||
cstring = ',long size_'+var+'_string'
|
||||
cstring2 = ',strlen(size_'+var+'_string)'
|
||||
if dims == ():
|
||||
if command == "":
|
||||
d = { 'type_short': t_short(type),
|
||||
'type': type,
|
||||
'ctype': f2c[t_short(type)],
|
||||
'cstring': cstring,
|
||||
'cstring2': cstring2,
|
||||
'type_set': type_set,
|
||||
'var': var,
|
||||
'group': group,
|
||||
'dims': strdims}
|
||||
print attributes%d
|
||||
print >>file_py, attributes_py%d
|
||||
else:
|
||||
d = { 'type': type,
|
||||
'var': var,
|
||||
'ctype': f2c[t_short(type)]+"*",
|
||||
'cstring': cstring,
|
||||
'group': group,
|
||||
'expr': command,
|
||||
'expr_py': command_py}
|
||||
buffer = calculated%d
|
||||
buffer = re.sub(r"at\((.*),(.*)\)",r'\1(\2)',buffer)
|
||||
print buffer
|
||||
print >>file_py, calculated_py%d
|
||||
elif type == "buffered":
|
||||
d = { 'group': group,
|
||||
'var': var,
|
||||
'dims_py': dims_py,
|
||||
'dims': dims }
|
||||
print buffered%d
|
||||
print >>file_py, buffered_py%d
|
||||
else:
|
||||
dims_loop = ''
|
||||
copy_loop = ''
|
||||
dims_loop_py = ''
|
||||
declar_loop = ' integer :: '
|
||||
for k,d in enumerate(dims):
|
||||
declar_loop += "i"+str(k+1)+","
|
||||
declar_loop = declar_loop[:-1]
|
||||
for k,d in enumerate(dims):
|
||||
dims_loop += " dims("+str(k+1)+") = "+str(d)+"\n"
|
||||
dims_loop_py += " dims["+str(k)+"] = "+str(d)+"\n"
|
||||
for k,d in enumerate(dims):
|
||||
copy_loop += k*" "+" do i"+str(k+1)+"=1,"+str(d)+'\n'
|
||||
copy_loop += (k+1)*" "+" %(var)s ("
|
||||
for k,d in enumerate(dims):
|
||||
copy_loop += "i"+str(k+1)+","
|
||||
copy_loop = copy_loop[:-1] + ") = %(group)s_%(var)s ("
|
||||
for k,d in enumerate(dims):
|
||||
copy_loop += "i"+str(k+1)+","
|
||||
copy_loop = copy_loop[:-1]%{'var': var,'group': group} + ")\n"
|
||||
for k,d in enumerate(dims):
|
||||
copy_loop += (len(dims)-k-1)*" "+" enddo\n"
|
||||
for g in groups.keys():
|
||||
dims_loop_py = dims_loop_py.replace(" "+g,' self.'+g)
|
||||
dims_loop_py = dims_loop_py.replace("*"+g,'*self.'+g)
|
||||
dims_loop_py = dims_loop_py.replace("/"+g,'/self.'+g)
|
||||
dims_loop_py = dims_loop_py.replace("+"+g,'+self.'+g)
|
||||
dims_loop_py = dims_loop_py.replace("-"+g,'-self.'+g)
|
||||
dims_loop_py = dims_loop_py.replace("("+g,'(self.'+g)
|
||||
d = { 'type_short': t_short(type),
|
||||
'type': type,
|
||||
'type_set': type_set,
|
||||
'var': var,
|
||||
'ctype': f2c[t_short(type)]+"*",
|
||||
'cstring': cstring,
|
||||
'group': group,
|
||||
'rank' : str(len(dims)),
|
||||
'dims': strdims,
|
||||
'dim_max': str(dim_max),
|
||||
'dims_loop': dims_loop,
|
||||
'dims_loop_py': dims_loop_py,
|
||||
'copy_loop': copy_loop,
|
||||
'declar_loop' : declar_loop}
|
||||
print attributes_arr%d
|
||||
print >>file_py, attributes_arr_py%d
|
||||
|
||||
file_py.close()
|
||||
|
||||
import create_ocaml
|
||||
create_ocaml.run()
|
||||
|
339
src/groups_templates.py
Normal file
339
src/groups_templates.py
Normal file
@ -0,0 +1,339 @@
|
||||
#!/usr/bin/python
|
||||
# EZFIO is an automatic generator of I/O libraries
|
||||
# Copyright (C) 2009 Anthony SCEMAMA, CNRS
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Anthony Scemama
|
||||
# LCPQ - IRSAMC - CNRS
|
||||
# Universite Paul Sabatier
|
||||
# 118, route de Narbonne
|
||||
# 31062 Toulouse Cedex 4
|
||||
# scemama@irsamc.ups-tlse.fr
|
||||
|
||||
|
||||
|
||||
#--------
|
||||
# Fortran
|
||||
#--------
|
||||
|
||||
path = """
|
||||
BEGIN_PROVIDER [ character*(128), path_%(group)s ]
|
||||
BEGIN_DOC
|
||||
! Path to the %(group)s group
|
||||
END_DOC
|
||||
|
||||
logical :: ezfio_exists
|
||||
|
||||
path_%(group)s = trim(libezfio_filename)//'/%(group)s'
|
||||
if (.not.ezfio_exists(path_%(group)s)) then
|
||||
if (.not.libezfio_read_only) then
|
||||
call ezfio_mkdir(path_%(group)s)
|
||||
endif
|
||||
endif
|
||||
|
||||
END_PROVIDER
|
||||
"""
|
||||
|
||||
attributes = """
|
||||
BEGIN_PROVIDER [ %(type)s, %(group)s_%(var)s ]
|
||||
BEGIN_DOC
|
||||
! %(var)s attribute of group %(group)s
|
||||
END_DOC
|
||||
|
||||
call ezfio_read_%(type_short)s(path_%(group)s,'%(var)s',%(group)s_%(var)s)
|
||||
|
||||
END_PROVIDER
|
||||
|
||||
subroutine ezfio_set_%(group)s_%(var)s(%(var)s)
|
||||
%(type_set)s :: %(var)s
|
||||
call ezfio_write_%(type_short)s(path_%(group)s,'%(var)s',%(var)s)
|
||||
FREE %(group)s_%(var)s
|
||||
end subroutine
|
||||
|
||||
subroutine ezfio_get_%(group)s_%(var)s(%(var)s)
|
||||
%(type)s :: %(var)s
|
||||
%(var)s = %(group)s_%(var)s
|
||||
end subroutine
|
||||
|
||||
subroutine ezfio_has_%(group)s_%(var)s(result)
|
||||
logical :: result
|
||||
inquire(file=trim(path_%(group)s)//'/%(var)s',exist=result)
|
||||
end subroutine
|
||||
|
||||
subroutine ezfio_free_%(group)s_%(var)s()
|
||||
FREE %(group)s_%(var)s
|
||||
end
|
||||
"""
|
||||
|
||||
attributes_arr = """
|
||||
BEGIN_PROVIDER [ %(type)s, %(group)s_%(var)s, %(dims)s ]
|
||||
BEGIN_DOC
|
||||
! %(var)s attribute of group %(group)s
|
||||
END_DOC
|
||||
|
||||
integer :: rank, dim_max, i
|
||||
integer :: dims(10)
|
||||
rank = %(rank)s
|
||||
%(dims_loop)s
|
||||
dim_max = %(dim_max)s
|
||||
call ezfio_read_array_%(type_short)s(path_%(group)s,'%(var)s', &
|
||||
rank,dims,dim_max,%(group)s_%(var)s)
|
||||
|
||||
END_PROVIDER
|
||||
|
||||
subroutine ezfio_set_%(group)s_%(var)s(%(var)s)
|
||||
%(type_set)s :: %(var)s (*)
|
||||
integer :: rank, dim_max, i
|
||||
integer :: dims(10)
|
||||
rank = %(rank)s
|
||||
character*(1024) :: message
|
||||
%(dims_loop)s
|
||||
call ezfio_write_array_%(type_short)s(path_%(group)s,'%(var)s', &
|
||||
rank,dims,%(dim_max)s,%(var)s)
|
||||
FREE %(group)s_%(var)s
|
||||
end subroutine
|
||||
|
||||
subroutine ezfio_get_%(group)s_%(var)s(%(var)s)
|
||||
%(type)s, intent(out) :: %(var)s (*)
|
||||
character*(1024) :: message
|
||||
%(var)s(1: %(dim_max)s ) = reshape ( %(group)s_%(var)s, (/ %(dim_max)s /) )
|
||||
end subroutine
|
||||
|
||||
subroutine ezfio_has_%(group)s_%(var)s(result)
|
||||
logical :: result
|
||||
inquire(file=trim(path_%(group)s)//'/%(var)s.gz',exist=result)
|
||||
end subroutine
|
||||
|
||||
subroutine ezfio_free_%(group)s_%(var)s()
|
||||
FREE %(group)s_%(var)s
|
||||
end
|
||||
"""
|
||||
|
||||
calculated="""
|
||||
BEGIN_PROVIDER [ %(type)s, %(group)s_%(var)s ]
|
||||
BEGIN_DOC
|
||||
! Calculated as %(expr)s
|
||||
END_DOC
|
||||
%(group)s_%(var)s = %(expr)s
|
||||
END_PROVIDER
|
||||
|
||||
subroutine ezfio_get_%(group)s_%(var)s(%(var)s)
|
||||
%(type)s, intent(out) :: %(var)s
|
||||
%(var)s = %(group)s_%(var)s
|
||||
end
|
||||
|
||||
subroutine ezfio_free_%(group)s_%(var)s()
|
||||
FREE %(group)s_%(var)s
|
||||
end
|
||||
"""
|
||||
|
||||
buffered="""
|
||||
subroutine ezfio_open_read_%(group)s_%(var)s()
|
||||
call ezfio_open_read_buffer(path_%(group)s,'%(var)s',%(dims)s)
|
||||
end
|
||||
|
||||
subroutine ezfio_open_write_%(group)s_%(var)s()
|
||||
call ezfio_open_write_buffer(path_%(group)s,'%(var)s',%(dims)s)
|
||||
end
|
||||
|
||||
subroutine ezfio_close_read_%(group)s_%(var)s()
|
||||
call ezfio_close_read_buffer(path_%(group)s,'%(var)s')
|
||||
end
|
||||
|
||||
subroutine ezfio_close_write_%(group)s_%(var)s()
|
||||
call ezfio_close_write_buffer(path_%(group)s,'%(var)s')
|
||||
end
|
||||
|
||||
subroutine ezfio_has_%(group)s_%(var)s(result)
|
||||
logical :: result
|
||||
inquire(file=trim(path_%(group)s)//'/%(var)s.gz',exist=result)
|
||||
end subroutine
|
||||
|
||||
subroutine ezfio_free_%(group)s_%(var)s()
|
||||
FREE %(group)s_%(var)s
|
||||
end
|
||||
"""
|
||||
|
||||
|
||||
|
||||
#---------
|
||||
# C
|
||||
#---------
|
||||
|
||||
attributes_c = """
|
||||
void ezfio_set_%(group)s_%(var)s(%(type)s %(var)s)
|
||||
{
|
||||
ezfio_set_%(group)s_%(var)s_(&%(var)s);
|
||||
}
|
||||
"""
|
||||
|
||||
c_header = """
|
||||
#ifndef EZFIO_H
|
||||
#define EZFIO_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
"""
|
||||
|
||||
c_footer = """
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
"""
|
||||
|
||||
|
||||
file_h = [c_header]
|
||||
file_h +=[ """
|
||||
void ezfio_set_file_(char* filename, long filename_size);
|
||||
|
||||
void ezfio_read_buffer_(int* indices,double* values, int* isize);
|
||||
void ezfio_write_buffer_(int* indices,double* values, int* isize);
|
||||
"""]
|
||||
|
||||
file_c = [ """
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int* indices;
|
||||
double* values;
|
||||
} sparse;
|
||||
|
||||
void ezfio_set_file(char* filename)
|
||||
{
|
||||
long len;
|
||||
len = strlen(filename);
|
||||
ezfio_set_file_(filename,mlen);
|
||||
}
|
||||
|
||||
sparse ezfio_read_buffer(int isize)
|
||||
{
|
||||
sparse result;
|
||||
ezfio_read_buffer_(result.indices,result.values,&isize);
|
||||
return result;
|
||||
}
|
||||
|
||||
void ezfio_write_buffer(sparse data, int isize)
|
||||
{
|
||||
ezfio_write_buffer_(data.indices,data.values,&isize);
|
||||
}
|
||||
|
||||
""" ]
|
||||
|
||||
|
||||
|
||||
#--------
|
||||
# Python
|
||||
#--------
|
||||
|
||||
path_py = """
|
||||
def get_path_%(group)s(self):
|
||||
result = self.filename.strip()+'/%(group)s'
|
||||
self.acquire_lock('%(group)s')
|
||||
try:
|
||||
if not self.exists(result):
|
||||
self.mkdir(result)
|
||||
finally:
|
||||
self.release_lock('%(group)s')
|
||||
return result
|
||||
|
||||
path_%(group)s = property(fget=get_path_%(group)s)
|
||||
"""
|
||||
|
||||
attributes_py = """
|
||||
def get_%(group)s_%(var)s(self):
|
||||
self.acquire_lock('%(group)s_%(var)s')
|
||||
try:
|
||||
result = self.read_%(type_short)s(self.path_%(group)s,'%(var)s')
|
||||
finally:
|
||||
self.release_lock('%(group)s_%(var)s')
|
||||
return result
|
||||
|
||||
def set_%(group)s_%(var)s(self,%(var)s):
|
||||
self.acquire_lock('%(group)s_%(var)s')
|
||||
try:
|
||||
self.write_%(type_short)s(self.path_%(group)s,'%(var)s',%(var)s)
|
||||
finally:
|
||||
self.release_lock('%(group)s_%(var)s')
|
||||
|
||||
%(group)s_%(var)s = property(fset=set_%(group)s_%(var)s, \
|
||||
fget=get_%(group)s_%(var)s)
|
||||
|
||||
def has_%(group)s_%(var)s(self):
|
||||
return (os.access(self.path_%(group)s+'/%(var)s',os.F_OK) == 1)
|
||||
"""
|
||||
|
||||
attributes_arr_py = """
|
||||
def get_%(group)s_%(var)s(self):
|
||||
rank = %(rank)s
|
||||
dims = range(rank)
|
||||
%(dims_loop_py)s
|
||||
dim_max = 1
|
||||
for d in dims:
|
||||
dim_max *= d
|
||||
self.acquire_lock('%(group)s_%(var)s')
|
||||
try:
|
||||
result = self.read_array_%(type_short)s(self.path_%(group)s,'%(var)s', rank,dims,dim_max)
|
||||
finally:
|
||||
self.release_lock('%(group)s_%(var)s')
|
||||
return result
|
||||
|
||||
def set_%(group)s_%(var)s(self,%(var)s):
|
||||
rank = %(rank)s
|
||||
dims = range(rank)
|
||||
%(dims_loop_py)s
|
||||
dim_max = 1
|
||||
for d in dims:
|
||||
dim_max *= d
|
||||
self.acquire_lock('%(group)s_%(var)s')
|
||||
try:
|
||||
self.write_array_%(type_short)s(self.path_%(group)s,'%(var)s', rank,dims,dim_max,%(var)s)
|
||||
finally:
|
||||
self.release_lock('%(group)s_%(var)s')
|
||||
|
||||
%(group)s_%(var)s = property(fset=set_%(group)s_%(var)s,fget=get_%(group)s_%(var)s)
|
||||
|
||||
def has_%(group)s_%(var)s(self):
|
||||
return (os.access(self.path_%(group)s+'/%(var)s.gz',os.F_OK) == 1)
|
||||
"""
|
||||
|
||||
calculated_py="""
|
||||
def get_%(group)s_%(var)s(self):
|
||||
return %(expr_py)s
|
||||
|
||||
%(group)s_%(var)s = property(fget=get_%(group)s_%(var)s)
|
||||
"""
|
||||
|
||||
buffered_py="""
|
||||
def open_read_%(group)s_%(var)s(self):
|
||||
self.open_read_buffer(self.path_%(group)s,'%(var)s',%(dims_py)s)
|
||||
|
||||
def open_write_%(group)s_%(var)s(self):
|
||||
self.open_write_buffer(self.path_%(group)s,'%(var)s',%(dims_py)s)
|
||||
|
||||
def close_read_%(group)s_%(var)s(self):
|
||||
self.close_buffer()
|
||||
|
||||
def close_write_%(group)s_%(var)s(self):
|
||||
self.close_buffer()
|
||||
|
||||
def has_%(group)s_%(var)s(self):
|
||||
return (os.access(self.path_%(group)s+'/%(var)s.gz',os.F_OK) == 1)
|
||||
"""
|
||||
|
||||
|
||||
|
42
src/libezfio_error.irp.f
Normal file
42
src/libezfio_error.irp.f
Normal file
@ -0,0 +1,42 @@
|
||||
! EZFIO is an automatic generator of I/O libraries
|
||||
! Copyright (C) 2009 Anthony SCEMAMA, CNRS
|
||||
!
|
||||
! This program is free software; you can redistribute it and/or modify
|
||||
! it under the terms of the GNU General Public License as published by
|
||||
! the Free Software Foundation; either version 2 of the License, or
|
||||
! (at your option) any later version.
|
||||
!
|
||||
! This program is distributed in the hope that it will be useful,
|
||||
! but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
! GNU General Public License for more details.
|
||||
!
|
||||
! You should have received a copy of the GNU General Public License along
|
||||
! with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
! 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
!
|
||||
! Anthony Scemama
|
||||
! LCPQ - IRSAMC - CNRS
|
||||
! Universite Paul Sabatier
|
||||
! 118, route de Narbonne
|
||||
! 31062 Toulouse Cedex 4
|
||||
! scemama@irsamc.ups-tlse.fr
|
||||
|
||||
subroutine ezfio_error(where,txt)
|
||||
implicit none
|
||||
character*(*) :: where
|
||||
character*(*) :: txt
|
||||
character*(128) :: fname
|
||||
|
||||
fname = libezfio_filename
|
||||
print *, '------------------------------------------------------------'
|
||||
print *, 'EZFIO File : '//trim(fname)
|
||||
print *, 'EZFIO Error in : '//trim(where)
|
||||
print *, '------------------------------------------------------------'
|
||||
print *, ''
|
||||
print *, trim(txt)
|
||||
print *, ''
|
||||
print *, '------------------------------------------------------------'
|
||||
stop
|
||||
end subroutine
|
||||
|
162
src/libezfio_file.irp.f
Normal file
162
src/libezfio_file.irp.f
Normal file
@ -0,0 +1,162 @@
|
||||
! EZFIO is an automatic generator of I/O libraries
|
||||
! Copyright (C) 2009 Anthony SCEMAMA, CNRS
|
||||
!
|
||||
! This program is free software; you can redistribute it and/or modify
|
||||
! it under the terms of the GNU General Public License as published by
|
||||
! the Free Software Foundation; either version 2 of the License, or
|
||||
! (at your option) any later version.
|
||||
!
|
||||
! This program is distributed in the hope that it will be useful,
|
||||
! but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
! GNU General Public License for more details.
|
||||
!
|
||||
! You should have received a copy of the GNU General Public License along
|
||||
! with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
! 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
!
|
||||
! Anthony Scemama
|
||||
! LCPQ - IRSAMC - CNRS
|
||||
! Universite Paul Sabatier
|
||||
! 118, route de Narbonne
|
||||
! 31062 Toulouse Cedex 4
|
||||
! scemama@irsamc.ups-tlse.fr
|
||||
|
||||
BEGIN_PROVIDER [ logical, libezfio_read_only ]
|
||||
BEGIN_DOC
|
||||
! If true, the EZFIO file is read-only
|
||||
END_DOC
|
||||
|
||||
libezfio_read_only = .False.
|
||||
END_PROVIDER
|
||||
|
||||
subroutine ezfio_set_read_only(v)
|
||||
logical :: v
|
||||
libezfio_read_only = v
|
||||
TOUCH libezfio_read_only
|
||||
end subroutine ezfio_set_read_only
|
||||
|
||||
subroutine ezfio_is_read_only(v)
|
||||
logical :: v
|
||||
v = libezfio_read_only
|
||||
end subroutine ezfio_is_read_only
|
||||
|
||||
integer function char_to_version(v)
|
||||
implicit none
|
||||
character*(32), intent(in) :: v
|
||||
character*(32) :: vnew
|
||||
integer :: i, j, k
|
||||
vnew=v
|
||||
do i=1,32
|
||||
if (vnew(i:i) == '.') then
|
||||
vnew(i:i) = ' '
|
||||
endif
|
||||
enddo
|
||||
read(vnew,*) i,j,k
|
||||
char_to_version = j*1000 + i*1000000
|
||||
end
|
||||
|
||||
BEGIN_PROVIDER [ character*(32), libezfio_version ]
|
||||
implicit none
|
||||
BEGIN_DOC
|
||||
! Version of the library
|
||||
END_DOC
|
||||
BEGIN_SHELL [/bin/sh]
|
||||
echo libezfio_version = \"`cat ../version | cut -d '=' -f 2` \"
|
||||
END_SHELL
|
||||
END_PROVIDER
|
||||
|
||||
BEGIN_PROVIDER [ character*(128), libezfio_filename ]
|
||||
implicit none
|
||||
BEGIN_DOC
|
||||
! Name of the EZFIO filesystem
|
||||
END_DOC
|
||||
|
||||
libezfio_filename = 'EZFIO_File'
|
||||
|
||||
END_PROVIDER
|
||||
|
||||
subroutine ezfio_get_filename(fname)
|
||||
implicit none
|
||||
character*(*) :: fname
|
||||
fname = libezfio_filename
|
||||
end subroutine
|
||||
|
||||
BEGIN_PROVIDER [ integer, libezfio_iunit ]
|
||||
implicit none
|
||||
BEGIN_DOC
|
||||
! Unit number for I/O access
|
||||
END_DOC
|
||||
|
||||
logical :: is_open
|
||||
is_open = .True.
|
||||
libezfio_iunit = 99
|
||||
do while (is_open)
|
||||
inquire(unit=libezfio_iunit,opened=is_open)
|
||||
if (is_open) then
|
||||
libezfio_iunit = libezfio_iunit-1
|
||||
endif
|
||||
if (libezfio_iunit == 9) then
|
||||
call ezfio_error(irp_here,'No more free file units!')
|
||||
endif
|
||||
enddo
|
||||
if ( (libezfio_iunit < 10).or.(libezfio_iunit > 99) ) then
|
||||
call ezfio_error(irp_here,'No more free units for files.')
|
||||
endif
|
||||
END_PROVIDER
|
||||
|
||||
logical function exists(path)
|
||||
implicit none
|
||||
character*(*) :: path
|
||||
character*(32) :: V
|
||||
inquire(file=trim(path)//'/.version',exist=exists)
|
||||
if (exists) then
|
||||
open(libezfio_iunit,file=trim(path)//'/.version')
|
||||
read(libezfio_iunit,*) V
|
||||
close(libezfio_iunit)
|
||||
! integer :: char_to_version
|
||||
! if (char_to_version(V) > char_to_version(libezfio_version)) then
|
||||
! call ezfio_error(irp_here, 'This file was generated with version '//trim(V)//&
|
||||
! ' but the current installed version is '//trim(libezfio_version)//'')
|
||||
! endif
|
||||
endif
|
||||
end function
|
||||
|
||||
subroutine ezfio_set_file(filename_in)
|
||||
implicit none
|
||||
|
||||
character*(*) :: filename_in
|
||||
|
||||
if (filename_in == '') then
|
||||
call ezfio_error(irp_here,'EZFIO file name is empty.')
|
||||
endif
|
||||
libezfio_filename = filename_in
|
||||
|
||||
logical :: exists
|
||||
if (.not.exists(libezfio_filename)) then
|
||||
call ezfio_mkdir(libezfio_filename)
|
||||
call ezfio_mkdir(trim(libezfio_filename)//'/ezfio')
|
||||
call system('LANG= date > '//trim(libezfio_filename)//'/ezfio/creation')
|
||||
call system('echo $USER > '//trim(libezfio_filename)//'/ezfio/user')
|
||||
BEGIN_SHELL [ /usr/bin/python ]
|
||||
import os
|
||||
command = "'echo %s > '//trim(libezfio_filename)//'/ezfio/library'"
|
||||
cwd = os.getcwd()
|
||||
cwd = cwd.split('src')[:-1]
|
||||
cwd = '/'.join(cwd)
|
||||
print "call system("+command%cwd+")"
|
||||
END_SHELL
|
||||
endif
|
||||
|
||||
TOUCH libezfio_filename
|
||||
end subroutine
|
||||
|
||||
subroutine ezfio_finish()
|
||||
implicit none
|
||||
close(libezfio_iunit)
|
||||
BEGIN_SHELL [ /usr/bin/python ]
|
||||
import os
|
||||
from zlib import crc32
|
||||
print ' call irp_finalize_%s'%(str(abs(crc32(os.getcwd()))))
|
||||
END_SHELL
|
||||
end
|
28
src/libezfio_groups.irp.f
Normal file
28
src/libezfio_groups.irp.f
Normal file
@ -0,0 +1,28 @@
|
||||
! EZFIO is an automatic generator of I/O libraries
|
||||
! Copyright (C) 2009 Anthony SCEMAMA, CNRS
|
||||
!
|
||||
! This program is free software; you can redistribute it and/or modify
|
||||
! it under the terms of the GNU General Public License as published by
|
||||
! the Free Software Foundation; either version 2 of the License, or
|
||||
! (at your option) any later version.
|
||||
!
|
||||
! This program is distributed in the hope that it will be useful,
|
||||
! but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
! GNU General Public License for more details.
|
||||
!
|
||||
! You should have received a copy of the GNU General Public License along
|
||||
! with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
! 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
!
|
||||
! Anthony Scemama
|
||||
! LCPQ - IRSAMC - CNRS
|
||||
! Universite Paul Sabatier
|
||||
! 118, route de Narbonne
|
||||
! 31062 Toulouse Cedex 4
|
||||
! scemama@irsamc.ups-tlse.fr
|
||||
|
||||
BEGIN_SHELL [ /usr/bin/python ]
|
||||
import groups
|
||||
END_SHELL
|
||||
|
473
src/libezfio_util.irp.f
Normal file
473
src/libezfio_util.irp.f
Normal file
@ -0,0 +1,473 @@
|
||||
! EZFIO is an automatic generator of I/O libraries
|
||||
! Copyright (C) 2009 Anthony SCEMAMA, CNRS
|
||||
!
|
||||
! This program is free software; you can redistribute it and/or modify
|
||||
! it under the terms of the GNU General Public License as published by
|
||||
! the Free Software Foundation; either version 2 of the License, or
|
||||
! (at your option) any later version.
|
||||
!
|
||||
! This program is distributed in the hope that it will be useful,
|
||||
! but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
! GNU General Public License for more details.
|
||||
!
|
||||
! You should have received a copy of the GNU General Public License along
|
||||
! with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
! 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
!
|
||||
! Anthony Scemama
|
||||
! LCPQ - IRSAMC - CNRS
|
||||
! Universite Paul Sabatier
|
||||
! 118, route de Narbonne
|
||||
! 31062 Toulouse Cedex 4
|
||||
! scemama@irsamc.ups-tlse.fr
|
||||
|
||||
BEGIN_PROVIDER [ integer, PID ]
|
||||
&BEGIN_PROVIDER [ character*(8), PID_str ]
|
||||
implicit none
|
||||
BEGIN_DOC
|
||||
! Current process ID
|
||||
END_DOC
|
||||
integer :: getpid
|
||||
PID = getpid()
|
||||
write(PID_str,'(I8.8)') PID
|
||||
END_PROVIDER
|
||||
|
||||
logical function ezfio_exists(path)
|
||||
implicit none
|
||||
character*(*) :: path
|
||||
inquire(file=trim(path)//'/.version',exist=ezfio_exists)
|
||||
if (ezfio_exists) then
|
||||
open(unit=libezfio_iunit,file=trim(path)//'/.version')
|
||||
character*(32) :: V
|
||||
read(libezfio_iunit,*) V
|
||||
close(libezfio_iunit)
|
||||
! integer :: char_to_version
|
||||
! if (char_to_version(V) > char_to_version(libezfio_version)) then
|
||||
! call ezfio_error(irp_here, "This file was generated with version "//trim(V)//&
|
||||
! " but the current installed version is "//trim(libezfio_version)//".")
|
||||
! endif
|
||||
endif
|
||||
end function
|
||||
|
||||
subroutine ezfio_mkdir(path)
|
||||
implicit none
|
||||
character*(*) :: path
|
||||
logical :: ezfio_exists
|
||||
if (libezfio_read_only) then
|
||||
call ezfio_error(irp_here,'Read-only file.')
|
||||
endif
|
||||
if (.not.ezfio_exists(path)) then
|
||||
call system('mkdir '//trim(path))
|
||||
open(unit=libezfio_iunit,file=trim(path)//'/.version')
|
||||
write(libezfio_iunit,'(A)') libezfio_version
|
||||
close(libezfio_iunit)
|
||||
endif
|
||||
|
||||
end subroutine
|
||||
|
||||
|
||||
subroutine libezfio_openz(filename,mode,err)
|
||||
implicit none
|
||||
character*(*) :: filename, mode
|
||||
character*(1024) :: fifo
|
||||
integer :: err
|
||||
fifo = trim(filename)//'.'//PID_str
|
||||
err=1
|
||||
|
||||
if (mode(1:1) == 'r') then
|
||||
call system('zcat '//trim(filename)//' > '//trim(fifo))
|
||||
open(unit=libezfio_iunit,file=trim(fifo),form='FORMATTED',action='READ')
|
||||
err=0
|
||||
else if (mode(1:1) == 'w') then
|
||||
open(unit=libezfio_iunit,file=trim(fifo),form='FORMATTED',action='WRITE')
|
||||
err=0
|
||||
else
|
||||
call ezfio_error(irp_here,'Mode '//trim(mode)//' is not implemented.')
|
||||
endif
|
||||
end
|
||||
|
||||
subroutine libezfio_closez(filename,mode)
|
||||
implicit none
|
||||
character*(*) :: filename, mode
|
||||
character*(1024) :: fifo
|
||||
fifo = trim(filename)//'.'//PID_str
|
||||
if (mode(1:1) == 'w') then
|
||||
close(unit=libezfio_iunit)
|
||||
call system('gzip -c < '//trim(fifo)//' > '//trim(filename))
|
||||
open(unit=libezfio_iunit,file=trim(fifo),form='FORMATTED',action='WRITE')
|
||||
endif
|
||||
close(unit=libezfio_iunit,status='DELETE')
|
||||
end
|
||||
|
||||
|
||||
BEGIN_SHELL [ /usr/bin/python ]
|
||||
from f_types import format, t_short
|
||||
|
||||
|
||||
template = """
|
||||
subroutine ezfio_read_%(type_short)s(dir,fil,dat)
|
||||
implicit none
|
||||
character*(*), intent(in) :: dir, fil
|
||||
%(type)s, intent(out) :: dat
|
||||
character*(1024) :: l_filename
|
||||
l_filename=trim(dir)//'/'//fil
|
||||
open(unit=libezfio_iunit,file=l_filename,form='FORMATTED', &
|
||||
action='READ',err=9)
|
||||
read(libezfio_iunit,%(fmt)s,end=9,err=9) dat
|
||||
close(libezfio_iunit)
|
||||
return
|
||||
9 continue
|
||||
call ezfio_error(irp_here,'Attribute '//trim(dir)//'/'//trim(fil)//' is not set')
|
||||
end
|
||||
|
||||
subroutine ezfio_write_%(type_short)s(dir,fil,dat)
|
||||
implicit none
|
||||
character*(*), intent(in) :: dir, fil
|
||||
%(type)s, intent(in) :: dat
|
||||
character*(1024) :: l_filename(2)
|
||||
if (libezfio_read_only) then
|
||||
call ezfio_error(irp_here,'Read-only file.')
|
||||
endif
|
||||
l_filename(1)=trim(dir)//'/.'//fil//'.'//PID_str
|
||||
l_filename(2)=trim(dir)//'/'//fil
|
||||
open(unit=libezfio_iunit,file=l_filename(1),form='FORMATTED',action='WRITE')
|
||||
write(libezfio_iunit,%(fmt)s) dat
|
||||
close(libezfio_iunit)
|
||||
call system( 'mv -f '//trim(l_filename(1))//' '//trim(l_filename(2)) )
|
||||
end
|
||||
|
||||
subroutine ezfio_read_array_%(type_short)s(dir,fil,rank,dims,dim_max,dat)
|
||||
implicit none
|
||||
character*(*), intent(in) :: dir, fil
|
||||
integer :: rank
|
||||
integer :: dims(rank)
|
||||
integer :: dim_max
|
||||
%(type)s :: dat(dim_max)
|
||||
integer :: err
|
||||
character*(1024) :: l_filename
|
||||
l_filename=trim(dir)//'/'//fil//'.gz'
|
||||
|
||||
err = 0
|
||||
call libezfio_openz(trim(l_filename),'rb',err)
|
||||
if (err == 0) then
|
||||
integer :: rank_read
|
||||
integer :: dims_read(rank), i
|
||||
|
||||
read(libezfio_iunit,'(I3)') rank_read
|
||||
if (rank_read /= rank) then
|
||||
call ezfio_error(irp_here,'Rank of data '//trim(l_filename)//&
|
||||
' different from array.')
|
||||
endif
|
||||
|
||||
if (err /= 0) then
|
||||
call ezfio_error(irp_here,'Error reading data in '//trim(l_filename)//&
|
||||
'.')
|
||||
endif
|
||||
read(libezfio_iunit,'(30(I20,X))') dims_read(1:rank)
|
||||
do i=1,rank
|
||||
if (dims_read(i) /= dims(i)) then
|
||||
call ezfio_error(irp_here,'Dimensions of data '//trim(l_filename)//&
|
||||
' different from array.')
|
||||
endif
|
||||
enddo
|
||||
|
||||
do i=1,dim_max
|
||||
if (err /= 0) then
|
||||
call ezfio_error(irp_here,'Error reading data in '//trim(l_filename)//&
|
||||
'.')
|
||||
endif
|
||||
read(libezfio_iunit,%(fmt)s) dat(i)
|
||||
enddo
|
||||
call libezfio_closez(trim(l_filename),'r')
|
||||
return
|
||||
else
|
||||
call ezfio_error(irp_here,'Attribute '//trim(l_filename)//' is not set')
|
||||
endif
|
||||
end
|
||||
subroutine ezfio_write_array_%(type_short)s(dir,fil,rank,dims,dim_max,dat)
|
||||
implicit none
|
||||
character*(*), intent(in) :: dir, fil
|
||||
integer, intent(in) :: rank
|
||||
integer, intent(in) :: dims(rank)
|
||||
integer, intent(in) :: dim_max
|
||||
%(type)s, intent(in) :: dat(dim_max)
|
||||
integer :: err
|
||||
character*(1024) :: l_filename(2)
|
||||
if (libezfio_read_only) then
|
||||
call ezfio_error(irp_here,'Read-only file.')
|
||||
endif
|
||||
l_filename(1)=trim(dir)//'/.'//fil//PID_str//'.gz'
|
||||
l_filename(2)=trim(dir)//'/'//fil//'.gz'
|
||||
|
||||
err = 0
|
||||
call libezfio_openz(trim(l_filename(1)),'wb',err)
|
||||
if (err == 0) then
|
||||
write(libezfio_iunit,'(I3)') rank
|
||||
write(libezfio_iunit,'(30(I20,X))') dims(1:rank)
|
||||
|
||||
integer :: i
|
||||
do i=1,dim_max
|
||||
write(libezfio_iunit,%(fmt)s) dat(i)
|
||||
enddo
|
||||
call libezfio_closez(trim(l_filename(1)),'w')
|
||||
endif
|
||||
call system( 'mv -f '//trim(l_filename(1))//' '//trim(l_filename(2)) )
|
||||
end
|
||||
"""
|
||||
|
||||
template_no_logical = """
|
||||
integer function n_count_%(type_short)s(array,isize,val)
|
||||
%(type)s, intent(in) :: array(*)
|
||||
integer, intent(in) :: isize
|
||||
%(type)s, intent(in) :: val
|
||||
|
||||
integer :: i
|
||||
n_count_%(type_short)s = 0
|
||||
do i=1,isize
|
||||
if (array(i) == val) then
|
||||
n_count_%(type_short)s = n_count_%(type_short)s +1
|
||||
endif
|
||||
enddo
|
||||
|
||||
end function
|
||||
! Build Python functions
|
||||
"""
|
||||
for t in format.keys():
|
||||
print template%{ 'type_short' : t_short(t), 'type' : t, 'fmt':format[t][0] }
|
||||
if t != "logical":
|
||||
print template_no_logical%{ 'type_short' : t_short(t), 'type' : t, 'fmt':format[t][0] }
|
||||
|
||||
template_py = """
|
||||
def read_%(type_short)s(self,dir,fil):
|
||||
conv = get_conv("%(type_short)s")
|
||||
l_filename=dir.strip()+'/'+fil
|
||||
try:
|
||||
file = open(l_filename,"r")
|
||||
except IOError:
|
||||
self.error('read_%(type_short)s',\
|
||||
'Attribute '+dir.strip()+'/'+fil+' is not set')
|
||||
dat = file.readline().strip()
|
||||
try:
|
||||
dat = conv(dat)
|
||||
except SyntaxError:
|
||||
pass
|
||||
file.close()
|
||||
return dat
|
||||
|
||||
def write_%(type_short)s(self,dir,fil,dat):
|
||||
if self.read_only:
|
||||
self.error('Read-only file.')
|
||||
conv = get_conv("%(type_short)s")
|
||||
l_filename= [ dir.strip()+'/.'+fil ]
|
||||
l_filename += [ dir.strip()+'/'+fil ]
|
||||
dat = conv(dat)
|
||||
file = open(l_filename[0],'w')
|
||||
print >>file,'%(fmt)s'%%(dat,)
|
||||
file.close()
|
||||
os.rename(l_filename[0],l_filename[1])
|
||||
|
||||
def read_array_%(type_short)s(self,dir,fil,rank,dims,dim_max):
|
||||
l_filename=dir.strip()+'/'+fil+'.gz'
|
||||
conv = get_conv("%(type_short)s")
|
||||
try:
|
||||
file = GzipFile(filename=l_filename,mode='rb')
|
||||
lines = file.read().splitlines()
|
||||
rank_read = int(lines[0])
|
||||
assert (rank_read == rank)
|
||||
|
||||
dims_read = map(int,lines[1].split())
|
||||
|
||||
for i,j in zip(dims_read,dims):
|
||||
assert i == j
|
||||
|
||||
lines.pop(0)
|
||||
lines.pop(0)
|
||||
dat = map(conv,lines)
|
||||
|
||||
file.close()
|
||||
return reshape(dat,dims)
|
||||
|
||||
except IOError:
|
||||
self.error('read_array_%(type_short)s', 'Attribute '+l_filename+' is not set')
|
||||
|
||||
def write_array_%(type_short)s(self,dir,fil,rank,dims,dim_max,dat):
|
||||
if self.read_only:
|
||||
self.error('Read-only file.')
|
||||
l_filename = [ tempfile.mktemp(dir=dir.strip()), dir.strip()+'/'+fil+'.gz' ]
|
||||
try:
|
||||
file = StringIO.StringIO()
|
||||
file.write("%%3d\\n"%%(rank,))
|
||||
for d in dims:
|
||||
file.write("%%20d "%%(d,))
|
||||
file.write("\\n")
|
||||
|
||||
dat = flatten(dat)
|
||||
for i in xrange(dim_max):
|
||||
file.write("%(fmt)s\\n"%%(dat[i],))
|
||||
file.flush()
|
||||
buffer = file.getvalue()
|
||||
file.close()
|
||||
file = GzipFile(filename=l_filename[0],mode='wb')
|
||||
file.write(buffer)
|
||||
file.close()
|
||||
os.rename(l_filename[0],l_filename[1])
|
||||
except:
|
||||
self.error("write_array_%(type_short)s",
|
||||
"Unable to write "+l_filename[1])
|
||||
"""
|
||||
|
||||
file_py = open("libezfio_util-gen.py","w")
|
||||
for t in format.keys():
|
||||
print >>file_py, template_py%{ 'type_short' : t_short(t), 'type' : t, 'fmt':format[t][1] }
|
||||
|
||||
import os
|
||||
command = "'echo %s > '//libezfio_filename//'/ezfio/last_library'"
|
||||
cwd = os.getcwd()
|
||||
cwd = cwd.split('src')[:-1]
|
||||
cwd = '/'.join(cwd)
|
||||
print >>file_py, """
|
||||
LIBRARY = "%s"
|
||||
"""%cwd
|
||||
|
||||
file_py.close()
|
||||
END_SHELL
|
||||
|
||||
BEGIN_PROVIDER [ integer, libezfio_buffer_rank ]
|
||||
BEGIN_DOC
|
||||
! Rank of the buffer ready for reading
|
||||
END_DOC
|
||||
libezfio_buffer_rank = -1
|
||||
END_PROVIDER
|
||||
|
||||
subroutine ezfio_open_write_buffer(dir,fil,rank)
|
||||
implicit none
|
||||
character*(*),intent(in) :: dir
|
||||
character*(*),intent(in) :: fil
|
||||
integer,intent(in) :: rank
|
||||
character*(1024) :: l_filename
|
||||
if (libezfio_read_only) then
|
||||
call ezfio_error(irp_here,'Read-only file.')
|
||||
endif
|
||||
l_filename=trim(dir)//'/'//fil//'.gz'
|
||||
|
||||
if (libezfio_buffer_rank /= -1) then
|
||||
call ezfio_error(irp_here,'Another buffered file is already open.')
|
||||
endif
|
||||
|
||||
libezfio_buffer_rank = rank
|
||||
if (libezfio_buffer_rank <= 0) then
|
||||
call ezfio_error(irp_here,'In file '//trim(l_filename)//': rank <= 0.')
|
||||
endif
|
||||
TOUCH libezfio_buffer_rank
|
||||
|
||||
integer :: err
|
||||
call libezfio_openz(trim(l_filename),'wb',err)
|
||||
if (err /= 0) then
|
||||
call ezfio_error(irp_here,'Unable to open buffered file '//trim(l_filename)//'.')
|
||||
endif
|
||||
|
||||
write(libezfio_iunit,'(I2)') rank
|
||||
|
||||
end
|
||||
|
||||
subroutine ezfio_open_read_buffer(dir,fil,rank)
|
||||
implicit none
|
||||
character*(*),intent(in) :: dir
|
||||
character*(*),intent(in) :: fil
|
||||
integer,intent(in) :: rank
|
||||
character*(1024) :: l_filename
|
||||
l_filename=trim(dir)//'/'//fil//'.gz'
|
||||
|
||||
if (libezfio_buffer_rank /= -1) then
|
||||
call ezfio_error(irp_here,'Another buffered file is already open.')
|
||||
endif
|
||||
|
||||
integer :: err
|
||||
call libezfio_openz(trim(l_filename),'rb',err)
|
||||
if (err /= 0) then
|
||||
print *, err, l_filename
|
||||
call ezfio_error(irp_here,'Unable to open buffered file '//trim(l_filename)//'.')
|
||||
endif
|
||||
|
||||
if (err /= 0) then
|
||||
print *, err, l_filename
|
||||
call ezfio_error(irp_here,'Unable to read buffered file '//trim(l_filename)//'.')
|
||||
endif
|
||||
|
||||
read(libezfio_iunit,'(I2)') libezfio_buffer_rank
|
||||
if (libezfio_buffer_rank /= rank) then
|
||||
call ezfio_error(irp_here,'In file '//trim(l_filename)//': Rank is not correct')
|
||||
endif
|
||||
TOUCH libezfio_buffer_rank
|
||||
|
||||
end
|
||||
|
||||
subroutine ezfio_close_read_buffer(dir,fil,rank)
|
||||
implicit none
|
||||
character*(*),intent(in) :: dir
|
||||
character*(*),intent(in) :: fil
|
||||
integer,intent(in) :: rank
|
||||
character*(1024) :: l_filename
|
||||
l_filename=trim(dir)//'/'//fil//'.gz'
|
||||
ASSERT (libezfio_buffer_rank > 0)
|
||||
call libezfio_closez(l_filename,'r')
|
||||
FREE libezfio_buffer_rank
|
||||
end
|
||||
|
||||
subroutine ezfio_close_write_buffer(dir,fil,rank)
|
||||
implicit none
|
||||
character*(*),intent(in) :: dir
|
||||
character*(*),intent(in) :: fil
|
||||
integer,intent(in) :: rank
|
||||
character*(1024) :: l_filename
|
||||
l_filename=trim(dir)//'/'//fil//'.gz'
|
||||
ASSERT (libezfio_buffer_rank > 0)
|
||||
call libezfio_closez(l_filename,'w')
|
||||
FREE libezfio_buffer_rank
|
||||
end
|
||||
|
||||
subroutine ezfio_read_buffer(indices,values,isize)
|
||||
implicit none
|
||||
|
||||
integer, intent(inout) :: isize
|
||||
integer, intent(out) :: indices(*)
|
||||
double precision, intent(out) :: values(isize)
|
||||
|
||||
integer :: i, j
|
||||
|
||||
if (libezfio_buffer_rank == -1) then
|
||||
call ezfio_error(irp_here,'No buffered file is open.')
|
||||
endif
|
||||
|
||||
do i=1,isize
|
||||
read(libezfio_iunit,err=10) (indices((i-1)*libezfio_buffer_rank+j), j=1,libezfio_buffer_rank), values(i)
|
||||
enddo
|
||||
return
|
||||
10 continue
|
||||
isize=i-1
|
||||
end
|
||||
|
||||
subroutine ezfio_write_buffer(indices,values,isize)
|
||||
implicit none
|
||||
|
||||
integer, intent(in) :: isize
|
||||
integer, intent(in) :: indices(*)
|
||||
double precision, intent(in) :: values(isize)
|
||||
|
||||
character*(80) :: cformat
|
||||
integer :: i, j, k, num, imax, l1, l2
|
||||
|
||||
if (libezfio_read_only) then
|
||||
call ezfio_error(irp_here,'Read-only file.')
|
||||
endif
|
||||
if (libezfio_buffer_rank == -1) then
|
||||
call ezfio_error(irp_here,'No buffered file is open.')
|
||||
endif
|
||||
|
||||
write(cformat,*) '(',num,'(',libezfio_buffer_rank,'(I4,X),E24.15,A1))'
|
||||
write(libezfio_iunit,cformat) ((indices((i-1)*libezfio_buffer_rank+j), j=1,libezfio_buffer_rank), &
|
||||
values(i), i=1,isize)
|
||||
|
||||
end
|
||||
|
87
src/read_config.py
Normal file
87
src/read_config.py
Normal file
@ -0,0 +1,87 @@
|
||||
#!/usr/bin/python
|
||||
# EZFIO is an automatic generator of I/O libraries
|
||||
# Copyright (C) 2009 Anthony SCEMAMA, CNRS
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Anthony Scemama
|
||||
# LCPQ - IRSAMC - CNRS
|
||||
# Universite Paul Sabatier
|
||||
# 118, route de Narbonne
|
||||
# 31062 Toulouse Cedex 4
|
||||
# scemama@irsamc.ups-tlse.fr
|
||||
|
||||
|
||||
# Read ezfio config file
|
||||
#----------------------
|
||||
|
||||
import os, sys
|
||||
lines = []
|
||||
for filename in [ '../config/'+i for i in os.listdir('../config')]:
|
||||
file = open(filename,'r')
|
||||
lines += map(lambda x: (x,filename), file.readlines())
|
||||
try:
|
||||
if lines[-1] != '':
|
||||
lines.append( ('', filename) )
|
||||
except:
|
||||
pass
|
||||
file.close()
|
||||
|
||||
import re
|
||||
|
||||
groups = {}
|
||||
group = None
|
||||
my_list = []
|
||||
for line, filename in lines:
|
||||
try:
|
||||
|
||||
if len(line.strip()) == 0:
|
||||
groups[group] = my_list
|
||||
elif line[0] != ' ': # New group
|
||||
group = line.strip()
|
||||
if group in groups.keys():
|
||||
my_list = groups[group]
|
||||
else:
|
||||
my_list = []
|
||||
else:
|
||||
line = line.replace("double precision","double_precision")
|
||||
line = line.split('=')
|
||||
if len(line) == 1:
|
||||
command = ""
|
||||
else:
|
||||
command = line[1].strip()
|
||||
line = line[0]
|
||||
buffer = line.split()
|
||||
if len(buffer) == 2:
|
||||
buffer += ["()"]
|
||||
else:
|
||||
buffer[2] = re.sub(r"\)",r',)',buffer[2])
|
||||
if buffer[1] == "double_precision":
|
||||
buffer[1] = "double precision"
|
||||
buffer[2] = re.sub(r"([a-zA-Z0-9_\-\+*/]+)",r'"\1"',buffer[2])
|
||||
buffer[2] = eval(buffer[2])
|
||||
buffer.append(command)
|
||||
my_list.append(tuple(buffer))
|
||||
except:
|
||||
import sys, time
|
||||
print >>sys.stderr, ''
|
||||
print >>sys.stderr, '*'*80
|
||||
print >>sys.stderr, 'Error in EZFIO config file '+filename+' :'
|
||||
print >>sys.stderr, line
|
||||
print >>sys.stderr, '*'*80
|
||||
print >>sys.stderr, ''
|
||||
time.sleep(3)
|
||||
sys.exit(1)
|
||||
|
28
src/run.irp.f
Normal file
28
src/run.irp.f
Normal file
@ -0,0 +1,28 @@
|
||||
! EZFIO is an automatic generator of I/O libraries
|
||||
! Copyright (C) 2009 Anthony SCEMAMA, CNRS
|
||||
!
|
||||
! This program is free software; you can redistribute it and/or modify
|
||||
! it under the terms of the GNU General Public License as published by
|
||||
! the Free Software Foundation; either version 2 of the License, or
|
||||
! (at your option) any later version.
|
||||
!
|
||||
! This program is distributed in the hope that it will be useful,
|
||||
! but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
! GNU General Public License for more details.
|
||||
!
|
||||
! You should have received a copy of the GNU General Public License along
|
||||
! with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
! 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
!
|
||||
! Anthony Scemama
|
||||
! LCPQ - IRSAMC - CNRS
|
||||
! Universite Paul Sabatier
|
||||
! 118, route de Narbonne
|
||||
! 31062 Toulouse Cedex 4
|
||||
! scemama@irsamc.ups-tlse.fr
|
||||
|
||||
program run
|
||||
! Leave this empty
|
||||
end
|
||||
|
50
src/test.py
Executable file
50
src/test.py
Executable file
@ -0,0 +1,50 @@
|
||||
#!/usr/bin/python
|
||||
# EZFIO is an automatic generator of I/O libraries
|
||||
# Copyright (C) 2009 Anthony SCEMAMA, CNRS
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
#
|
||||
# Anthony Scemama
|
||||
# LCPQ - IRSAMC - CNRS
|
||||
# Universite Paul Sabatier
|
||||
# 118, route de Narbonne
|
||||
# 31062 Toulouse Cedex 4
|
||||
# scemama@irsamc.ups-tlse.fr
|
||||
|
||||
|
||||
from ezfio import ezfio
|
||||
|
||||
EZFIO=ezfio
|
||||
|
||||
EZFIO.set_file('icule')
|
||||
EZFIO.set_system_num_alpha(4)
|
||||
EZFIO.set_geometry_num_atom(5)
|
||||
x = [ "label"+str(i) for i in range(5) ]
|
||||
indices = [ [ 1, 2, 3, 4 ], [ 5, 6, 7, 8] ]
|
||||
values = [ 10., 20.]
|
||||
isize = len(indices)
|
||||
EZFIO.open_write_ao_two_int()
|
||||
EZFIO.write_buffer(indices,values,isize)
|
||||
EZFIO.write_buffer(indices,values,isize)
|
||||
EZFIO.close_write_ao_two_int()
|
||||
indices = []
|
||||
values = []
|
||||
isize = 5
|
||||
EZFIO.open_read_ao_two_int()
|
||||
indices,values = EZFIO.read_buffer(isize)
|
||||
print indices
|
||||
print values
|
||||
EZFIO.close_read_ao_two_int()
|
||||
|
Loading…
Reference in New Issue
Block a user