diff --git a/README.html b/README.html index 9ca26a8..fd76342 100644 --- a/README.html +++ b/README.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + TREXIO source code documentation @@ -342,7 +342,7 @@ and bug reports should be submitted at

Author: TREX-CoE

-

Created: 2021-09-13 Mon 16:10

+

Created: 2021-09-14 Tue 09:40

Validate

diff --git a/Sparse.html b/Sparse.html index dd9b5c5..55388a8 100644 --- a/Sparse.html +++ b/Sparse.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + @@ -232,8 +232,8 @@ for the JavaScript code in this tag.

Table of Contents

@@ -241,8 +241,8 @@ for the JavaScript code in this tag. See templatorfront.org

-
-

1 Text back end

+
+

1 Text back end

As the size of the dataset should be extensible, the simplest @@ -256,8 +256,8 @@ The offset can be used with fseek(69L*offset, SEEK_SET)

-
-

2 HDF5 Back end

+
+

2 HDF5 Back end

We need to declare the number of rows of the dataset as @@ -278,7 +278,7 @@ If the offset+num > nmax, we need to extend the dataset.

-

Created: 2021-09-13 Mon 16:10

+

Created: 2021-09-14 Tue 09:40

Validate

diff --git a/index.html b/index.html index 9ca26a8..fd76342 100644 --- a/index.html +++ b/index.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + TREXIO source code documentation @@ -342,7 +342,7 @@ and bug reports should be submitted at

Author: TREX-CoE

-

Created: 2021-09-13 Mon 16:10

+

Created: 2021-09-14 Tue 09:40

Validate

diff --git a/templator_front.html b/templator_front.html index 385c6fb..b4b845f 100644 --- a/templator_front.html +++ b/templator_front.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + Front end API @@ -333,61 +333,106 @@ for the JavaScript code in this tag.

Table of Contents

+ +
  • 3. Templates for front end + +
  • +
  • 4. Fortran helper/wrapper functions
  • -
    -

    1 Coding conventions

    +
    +

    1 Coding conventions

    • integer types will be defined using types given in stdint.h
    • @@ -402,8 +447,8 @@ for the JavaScript code in this tag.
    -
    -

    1.1 Memory allocation

    +
    +

    1.1 Memory allocation

    Memory allocation of structures can be facilitated by using the @@ -438,8 +483,8 @@ The maximum string size for the filenames is 4096 characters.

    -
    -

    2 Front end

    +
    +

    2 Front end

    All calls to TREXIO are thread-safe. @@ -447,10 +492,10 @@ TREXIO front end is modular, which simplifies implementation of new back ends.

    -
    -

    2.1 Error handling

    +
    +

    2.1 Error handling

    - +
    @@ -555,7 +600,7 @@ TREXIO front end is modular, which simplifies implementation of new back ends. - + @@ -612,6 +657,24 @@ TREXIO front end is modular, which simplifies implementation of new back ends. + + + + + + + + + + + + + + + + + + @@ -620,16 +683,49 @@ TREXIO front end is modular, which simplifies implementation of new back ends.
    TREXIO_ATTR_ALREADY_EXISTS 13'Attribute (num/str) already exists''Attribute already exists'
    'Error writing element'
    TREXIO_UNSAFE_ARRAY_DIM23'Access to memory beyond allocated'
    TREXIO_ATTR_MISSING24'Attribute does not exist in the file'
    TREXIO_DSET_MISSING25'Dataset does not exist in the file'
    TREXIO_INVALID_STR_LEN 30
    +
    +
    """ This script generates the C and Fortran constants for the error
    +    codes from the org-mode table.
    +"""
    +
    +result = [ "#+begin_src c :tangle prefix_front.h :exports none" ]
    +for (text, code,_) in table:
    +  text=text.replace("~","")
    +  result += [ f"#define {text:30s} ((trexio_exit_code) {code:d})" ]
    +result += [ "#+end_src" ]
    +
    +result += [ "" ]
    +
    +result += [ "#+begin_src f90 :tangle prefix_fortran.f90 :exports none" ]
    +for (text, code,_) in table:
    +  text=text.replace("~","")
    +  result += [ f"   integer(trexio_exit_code), parameter :: {text:30s} = {code:d}" ]
    +result += [ "#+end_src" ]
    +
    +result += [ "" ]
    +
    +result += [ "#+begin_src python :tangle prefix_python.py :exports none" ]
    +result += [ "# define TREXIO exit codes" ]
    +for (text, code,_) in table:
    +  text=text.replace("~","")
    +  result += [ f"{text:30s} = {code:d}" ]
    +result += [ "#+end_src" ]
    +
    +return '\n'.join(result)
    +
    +
    +
    +
    + +
    +

    2.1.1 Decoding errors

    +

    The trexio_string_of_error converts an exit code into a string. The string is assumed to be large enough to contain the error message (typically 128 characters).

    -

    -◉ Decoding errors -

    -

    To decode the error messages, trexio_string_of_error converts an error code into a string. @@ -643,87 +739,100 @@ error code into a string.

    The text strings are extracted from the previous table.

    +
    +
    +
    2.1.1.1 C source code
    +
    const char*
     trexio_string_of_error (const trexio_exit_code error)
     {
       switch (error) {
       case TREXIO_FAILURE:
    -          return "Unknown failure";
    -          break;
    +    return "Unknown failure";
    +    break;
       case TREXIO_SUCCESS:
    -          return "Success";
    -          break;
    +    return "Success";
    +    break;
       case TREXIO_INVALID_ARG_1:
    -          return "Invalid argument 1";
    -          break;
    +    return "Invalid argument 1";
    +    break;
       case TREXIO_INVALID_ARG_2:
    -          return "Invalid argument 2";
    -          break;
    +    return "Invalid argument 2";
    +    break;
       case TREXIO_INVALID_ARG_3:
    -          return "Invalid argument 3";
    -          break;
    +    return "Invalid argument 3";
    +    break;
       case TREXIO_INVALID_ARG_4:
    -          return "Invalid argument 4";
    -          break;
    +    return "Invalid argument 4";
    +    break;
       case TREXIO_INVALID_ARG_5:
    -          return "Invalid argument 5";
    -          break;
    +    return "Invalid argument 5";
    +    break;
       case TREXIO_END:
    -          return "End of file";
    -          break;
    +    return "End of file";
    +    break;
       case TREXIO_READONLY:
    -          return "Read-only file";
    -          break;
    +    return "Read-only file";
    +    break;
       case TREXIO_ERRNO:
    -          return strerror(errno);
    -          break;
    +    return strerror(errno);
    +    break;
       case TREXIO_INVALID_ID:
    -          return "Invalid ID";
    -          break;
    +    return "Invalid ID";
    +    break;
       case TREXIO_ALLOCATION_FAILED:
    -          return "Allocation failed";
    -          break;
    +    return "Allocation failed";
    +    break;
       case TREXIO_HAS_NOT:
    -          return "Element absent";
    -          break;
    +    return "Element absent";
    +    break;
       case TREXIO_INVALID_NUM:
    -          return "Invalid dimensions";
    -          break;
    +    return "Invalid dimensions";
    +    break;
       case TREXIO_ATTR_ALREADY_EXISTS:
    -          return "Attribute (num/str) already exists";
    -          break;
    +    return "Attribute already exists";
    +    break;
       case TREXIO_DSET_ALREADY_EXISTS:
    -          return "Dataset already exists";
    -          break;
    +    return "Dataset already exists";
    +    break;
       case TREXIO_OPEN_ERROR:
    -          return "Error opening file";
    -          break;
    +    return "Error opening file";
    +    break;
       case TREXIO_LOCK_ERROR:
    -          return "Error locking file";
    -          break;
    +    return "Error locking file";
    +    break;
       case TREXIO_UNLOCK_ERROR:
    -          return "Error unlocking file";
    -          break;
    +    return "Error unlocking file";
    +    break;
       case TREXIO_FILE_ERROR:
    -          return "Invalid file handle";
    -          break;
    +    return "Invalid file handle";
    +    break;
       case TREXIO_GROUP_READ_ERROR:
    -          return "Error reading group";
    -          break;
    +    return "Error reading group";
    +    break;
       case TREXIO_GROUP_WRITE_ERROR:
    -          return "Error writing group";
    -          break;
    +    return "Error writing group";
    +    break;
       case TREXIO_ELEM_READ_ERROR:
    -          return "Error reading element";
    -          break;
    +    return "Error reading element";
    +    break;
       case TREXIO_ELEM_WRITE_ERROR:
    -          return "Error writing element";
    -          break;
    +    return "Error writing element";
    +    break;
    +  case TREXIO_UNSAFE_ARRAY_DIM:
    +    return "Access to memory beyond allocated";
    +    break;
    +  case TREXIO_ATTR_MISSING:
    +    return "Attribute does not exist in the file";
    +    break;
    +  case TREXIO_DSET_MISSING:
    +    return "Dataset does not exist in the file";
    +    break;
       case TREXIO_INVALID_STR_LEN:
    -          return "Invalid max_str_len";
    -          break;
    +    return "Invalid max_str_len";
    +    break;
       }
       return "Unknown error";
     }
    @@ -735,7 +844,12 @@ The text strings are extracted from the previous table.
     }
     
    +
    +
    +
    +
    2.1.1.2 Fortran interface
    +
    interface
        subroutine trexio_string_of_error (error, string) bind(C, name='trexio_string_of_error_f')
    @@ -750,8 +864,48 @@ The text strings are extracted from the previous table.
     
    -
    -

    2.2 Back ends

    +
    +
    2.1.1.3 Python interface
    +
    +
    +
    class Error(Exception):
    +    """Base class for TREXIO errors.
    +
    +    Attributes:
    +       error: int -- exit code returned by the call to TREXIO library;
    +       message: str -- decoded string corresponding to trexio_exit_code.
    +
    +    """
    +
    +    def __init__(self, trexio_return_code):
    +        self.error = trexio_return_code
    +        self.message = string_of_error(trexio_return_code)
    +        super().__init__(self.message)
    +
    +
    +def string_of_error(return_code: int) -> str:
    +    """Decode the TREXIO exit code.
    +
    +    Argument is an integer return code that correspond to one of the TREXIO errors.
    +
    +    Returns string that contains description of TREXIO ~return_code~.
    +    """
    +
    +    try:
    +        error_str = pytr.trexio_string_of_error(return_code)
    +    except:
    +        raise 
    +
    +    return error_str
    +
    +
    +
    +
    +
    +
    + +
    +

    2.2 Back ends

    TREXIO has several back ends: @@ -770,6 +924,14 @@ Then the corresponding back-end has/read/write functions has to be lines that correspond to the TREXIO_JSON back end (not implemented yet).

    +

    +Note: It is important to increment the value of TREXIOINVALIDBACKEND when a new back end is added. Otherwise, it will not be available. +

    +
    + +
    +

    2.2.1 C

    +
    typedef int32_t back_end_t;
     
    @@ -783,8 +945,37 @@ lines that correspond to the TREXIO_JSON back end (not implemented
     
    -
    -

    2.3 Read/write behavior

    + +
    +

    2.2.2 Fortran

    +
    +
    +
      integer(trexio_backend), parameter :: TREXIO_HDF5 = 0
    +  integer(trexio_backend), parameter :: TREXIO_TEXT = 1
    +! integer(trexio_backend), parameter :: TREXIO_JSON = 2
    +  integer(trexio_backend), parameter :: TREXIO_INVALID_BACK_END = 2
    +
    +
    +
    +
    + +
    +

    2.2.3 Python

    +
    +
    +
    # define TREXIO back ends
    +TREXIO_HDF5 = 0
    +TREXIO_TEXT = 1
    +#TREXIO_JSON = 2
    +TREXIO_INVALID_BACK_END = 2
    +
    +
    +
    +
    +
    + +
    +

    2.3 Read/write behavior

    Every time a reading function is called, the data is read from the @@ -812,8 +1003,8 @@ concurrent programs, the behavior is not specified.

    -
    -

    2.4 TREXIO file type

    +
    +

    2.4 TREXIO file type

    trexio_s is the the main type for TREXIO files, visible to the users @@ -846,9 +1037,83 @@ TREXIO files will have as a first argument the TREXIO file handle.

    + +
    +

    2.4.1 TREXIOFile Python class

    +
    +
    +
    class File:
    +    """TREXIO File object.
    +
    +    General information about the TREXIO file.
    +
    +    Parameters:
    +
    +    filename: str
    +        Is a name of the full path to the TREXIO file.
    +    back_end: int
    +        One of the currently supported TREXIO back ends.
    +        For example, TREXIO_HDF5 (0) or TREXIO_TEXT (1).
    +    mode: str
    +        One of the currently supported TREXIO open modes.
    +        For example, 'r' or 'w'.
    +    isOpen: bool
    +        Flag indicating whether the current object is still open for I/O
    +    pytrexio_s:
    +        A PyObject corresponding to SWIG proxy of the trexio_s struct in C.
    +        This argument is in fact a TREXIO file handle, which is required for
    +        communicating with the C back end. 
    +    info: dict
    +        Dictionary of key-value pairs with additional information about the file.
    +    """
    +
    +
    +    def __init__(self, filename, mode='r', back_end=TREXIO_HDF5,
    +                 pytrexio_s=None, info=None):
    +        """This is a TREXIO File constructor."""
    +
    +        self.filename = filename
    +        self.mode = mode
    +        self.back_end = back_end
    +
    +        self.isOpen = False 
    +        if pytrexio_s is None:
    +            self.pytrexio_s = open(filename, mode, back_end)
    +            self.isOpen = True
    +        else:
    +            self.pytrexio_s = pytrexio_s
    +            self.isOpen = None
    +
    +        self.info = info
    +
    +
    +    def close(self):
    +        """Close a TREXIO File."""
    +
    +        if self.isOpen:
    +            close(self.pytrexio_s)
    +            self.isOpen = False
    +        else:
    +            raise Exception("TREXIO File object has not been opened.")
    +
    +
    +    def __del__(self):
    +        """This is a TREXIO File destructor."""
    +
    +        if self.isOpen:
    +            close(self.pytrexio_s)
    +        elif self.isOpen is None:
    +            raise Exception("[WIP]: TREXIO file handle provided but what if the file is already closed?")
    +        else:
    +            pass 
    +
    -
    -

    2.5 Polymorphism of the file handle

    +
    +
    +
    + +
    +

    2.5 Polymorphism of the file handle

    Polymorphism of the trexio_t type is handled by ensuring that the @@ -867,8 +1132,8 @@ corresponding types for all back ends can be safely casted to

    -
    -

    2.6 File opening

    +
    +

    2.6 File opening

    trexio_open creates a new TREXIO file or opens existing one. @@ -905,7 +1170,11 @@ data). These names are populated by the generator.py (i.e. they are hard-coded), which is why the user should tend to avoid renaming the .txt data files.

    +
    +
    +

    2.6.1 C

    +
    trexio_t*
     trexio_open(const char* file_name, const char mode,
    @@ -963,6 +1232,10 @@ renaming the .txt data files.
       result->mode        = mode;
       result->one_based   = false;  // Need to be flipped in Fortran interface
       int irc = pthread_mutex_init ( &(result->thread_lock), NULL);
    +  if (irc != 0) {
    +    free(result);
    +    return NULL;
    +  }
       assert (irc == 0);
     
       trexio_exit_code rc;
    @@ -1051,7 +1324,12 @@ renaming the .txt data files.
     }
     
    +
    +
    +
    +

    2.6.2 Fortran

    +
    interface
        integer(8) function trexio_open_c (filename, mode, backend) bind(C, name="trexio_open")
    @@ -1064,7 +1342,50 @@ renaming the .txt data files.
     end interface
     
    +
    +
    +
    +

    2.6.3 Python

    +
    +
    +
    def open(file_name: str, mode: str, back_end: int):
    +    """Create TREXIO file or open existing one.
    +
    +    Parameters:
    +
    +    file_name: str
    +        Name of the TREXIO file
    +
    +    mode: str
    +        One of the currently supported ~open~ modes (e.g. 'w', 'r')
    +
    +    back_end: int
    +        One of the currently supported TREXIO back ends (e.g. TREXIO_HDF5, TREXIO_TEXT)    
    +
    +    Return: 
    +        SWIG object of type trexio_s.
    +
    +    Examples:
    +    >>> from trexio import open as tr_open
    +    >>> trex_file = tr_open("example.h5", "w", TREXIO_HDF5)
    +    """
    +
    +    try:
    +        trexio_file = pytr.trexio_open(file_name, mode, back_end)
    +        assert trexio_file is not None
    +    except AssertionError:
    +        raise Exception(f"Could not open TREXIO file {file_name} using trexio_open function. Please make sure that there are no typos in the file name.")
    +
    +    return trexio_file
    +
    +
    +
    +
    + +
    +

    2.6.4 Zero-based versus one-based arrays of indices

    +

    Because arrays are zero-based in Fortran, we need to set a flag to know if we need to shift by 1 arrays of indices. @@ -1094,9 +1415,10 @@ know if we need to shift by 1 arrays of indices.

    +
    -
    -

    2.7 File closing

    +
    +

    2.7 File closing

    trexio_close closes an existing trexio_t file. @@ -1111,7 +1433,11 @@ input parameters: output: trexio_exit_code exit code.

    +
    +
    +

    2.7.1 C

    +
    trexio_exit_code
     trexio_close (trexio_t* file)
    @@ -1178,7 +1504,12 @@ output:
     }
     
    +
    +
    +
    +

    2.7.2 Fortran

    +
    interface
        integer function trexio_close (trex_file) bind(C)
    @@ -1190,14 +1521,36 @@ output:
     
    + +
    +

    2.7.3 Python

    +
    +
    +
    def close(trexio_file):
    +    """Close TREXIO file.
    +
    +    Parameter is a ~trexio_file~ object that has been created by a call to ~open~ function.
    +    """
    +
    +    try:
    +        rc = pytr.trexio_close(trexio_file)
    +        if rc != TREXIO_SUCCESS:
    +            raise Error(rc)
    +    except:
    +        raise
    +
    +
    +
    +
    +
    -
    -

    3 Templates for front end

    +
    +

    3 Templates for front end

    -
    -

    3.1 Description

    +
    +

    3.1 Description

    Consider the following block of trex.json: @@ -1356,6 +1709,12 @@ each variable can be found below: Dimensions in Fortran (:,:) + + +$group_dset_py_dtype$ +Standard datatype of the dataset [Python] +float/int + @@ -1387,8 +1746,8 @@ or double precision for integer and floating point numbers.

    -
    -

    3.2 Templates for front end has/read/write a single dimensioning variable

    +
    +

    3.2 Templates for front end has/read/write a single dimensioning variable

    This section concerns API calls related to dimensioning variables. @@ -1457,8 +1816,8 @@ This section concerns API calls related to dimensioning variables.

    -
    -

    3.2.1 C templates for front end

    +
    +

    3.2.1 C templates for front end

    The C templates that correspond to each of the abovementioned @@ -1477,6 +1836,7 @@ precision (see Table above). trexio_read_$group_num$_64 (trexio_t* const file, int64_t* const num) { if (file == NULL) return TREXIO_INVALID_ARG_1; + if (trexio_has_$group_num$(file) != TREXIO_SUCCESS) return TREXIO_ATTR_MISSING; uint64_t u_num = 0; trexio_exit_code rc = TREXIO_GROUP_READ_ERROR; @@ -1539,6 +1899,7 @@ precision (see Table above). trexio_read_$group_num$_32 (trexio_t* const file, int32_t* const num) { if (file == NULL) return TREXIO_INVALID_ARG_1; + if (trexio_has_$group_num$(file) != TREXIO_SUCCESS) return TREXIO_ATTR_MISSING; uint64_t u_num = 0; trexio_exit_code rc = TREXIO_GROUP_READ_ERROR; @@ -1647,8 +2008,8 @@ precision (see Table above).

    -
    -

    3.2.2 Fortran templates for front end

    +
    +

    3.2.2 Fortran templates for front end

    The Fortran templates that provide an access to the C API calls from Fortran. @@ -1732,10 +2093,95 @@ These templates are based on the use of iso_c_binding. Pointers hav

    + +
    +

    3.2.3 Python templates for front end

    +
    +
    +
    def write_$group_num$(trexio_file, num_w: int) -> None: 
    +    """Write the $group_num$ variable in the TREXIO file.
    +
    +    Parameters:
    +
    +    trexio_file:
    +        TREXIO File object.
    +
    +    num_w: int
    +        Value of the $group_num$ variable to be written.
    +
    +    Raises:
    +        - Exception from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error.
    +        - Exception from some other error (e.g. RuntimeError).
    +    """
    +
    +    try:
    +        rc = pytr.trexio_write_$group_num$(trexio_file.pytrexio_s, num_w)
    +        if rc != TREXIO_SUCCESS:
    +            raise Error(rc)
    +    except:
    +        raise    
    +
    -
    -

    3.3 Templates for front end has/read/write a dataset of numerical data

    +
    +
    def read_$group_num$(trexio_file) -> int: 
    +    """Read the $group_num$ variable from the TREXIO file.
    +
    +    Parameter is a ~TREXIO File~ object that has been created by a call to ~open~ function.
    +
    +    Returns:
    +        ~num_r~: int
    +        Integer value of $group_num$ variable read from ~trexio_file~.
    +
    +    Raises:
    +        - Exception from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error.
    +        - Exception from some other error (e.g. RuntimeError).
    +    """
    +
    +    try:
    +        rc, num_r = pytr.trexio_read_$group_num$(trexio_file.pytrexio_s)
    +        if rc != TREXIO_SUCCESS:
    +            raise Error(rc)
    +    except:
    +        raise    
    +
    +    return num_r
    +
    +
    + +
    +
    def has_$group_num$(trexio_file) -> bool: 
    +    """Check that $group_num$ variable exists in the TREXIO file.
    +
    +    Parameter is a ~TREXIO File~ object that has been created by a call to ~open~ function.
    +
    +    Returns:
    +          True if the variable exists, False otherwise
    +
    +    Raises:
    +        - Exception from trexio.Error class if TREXIO return code ~rc~ is TREXIO_FAILURE and prints the error message using string_of_error.
    +        - Exception from some other error (e.g. RuntimeError).
    +    """
    +
    +    try:
    +        rc = pytr.trexio_has_$group_num$(trexio_file.pytrexio_s)
    +        if rc == TREXIO_FAILURE:
    +            raise Error(rc)
    +    except:
    +        raise    
    +
    +    if rc == TREXIO_SUCCESS:
    +        return True
    +    else:
    +        return False
    +
    +
    +
    +
    +
    + +
    +

    3.3 Templates for front end has/read/write a dataset of numerical data

    This section concerns API calls related to datasets. @@ -1767,45 +2213,57 @@ This section concerns API calls related to datasets. trexio_read_$group_dset$ -Read a dataset -Double +Read a dataset in default precision +Double/Single for float/int trexio_write_$group_dset$ -Write a dataset +Write a dataset in default precision +Double/Single for float/int + + + +trexio_read_safe_$group_dset$ +Read a bounded dataset +Double + + + +trexio_write_safe_$group_dset$ +Write a bounded dataset Double trexio_read_$group_dset$_32 -Read a dataset +Read a dataset in single precision Single trexio_write_$group_dset$_32 -Write a dataset +Write a dataset in single precision Single trexio_read_$group_dset$_64 -Read a dataset +Read a dataset in double precision Double trexio_write_$group_dset$_64 -Write a dataset +Write a dataset in double precision Double

    -
    -

    3.3.1 C templates for front end

    +
    +

    3.3.1 C templates for front end

    The C templates that correspond to each of the abovementioned functions can be found below. @@ -1814,8 +2272,16 @@ to/from the TREXIO file (except for trexio_has_ functi Suffixes _32 and _64 correspond to API calls dealing with single and double precision, respectively. The basic (non-suffixed) API call on datasets deals with double precision (see Table above).

    +
    + +
    +
    3.3.1.1 Function declarations
    +
    +
    +
    3.3.1.2 Source code for double precision functions
    +
    trexio_exit_code
     trexio_read_$group_dset$_64 (trexio_t* const file, $group_dset_dtype_double$* const $group_dset$)
    @@ -1823,13 +2289,13 @@ The basic (non-suffixed) API call on datasets deals with double precision (see T
     
       if (file  == NULL) return TREXIO_INVALID_ARG_1;
       if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2;
    +  if (trexio_has_$group_dset$(file) != TREXIO_SUCCESS) return TREXIO_DSET_MISSING;
     
       trexio_exit_code rc;
       int64_t $group_dset_dim$ = 0;
     
       /* Error handling for this call is added by the generator */
       rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$));
    -  if (rc != TREXIO_SUCCESS) return rc;
     
       if ($group_dset_dim$ == 0L) return TREXIO_INVALID_NUM;
     
    @@ -1872,6 +2338,7 @@ The basic (non-suffixed) API call on datasets deals with double precision (see T
     
    +
    trexio_exit_code
     trexio_write_$group_dset$_64 (trexio_t* const file, const $group_dset_dtype_double$* $group_dset$)
    @@ -1886,7 +2353,6 @@ The basic (non-suffixed) API call on datasets deals with double precision (see T
     
       /* Error handling for this call is added by the generator */
       rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$));
    -  if (rc != TREXIO_SUCCESS) return rc;
     
       if ($group_dset_dim$ == 0L) return TREXIO_INVALID_NUM;
     
    @@ -1939,7 +2405,12 @@ The basic (non-suffixed) API call on datasets deals with double precision (see T
     }
     
    +
    +
    +
    +
    3.3.1.3 Source code for single precision functions
    +
    trexio_exit_code
     trexio_read_$group_dset$_32 (trexio_t* const file, $group_dset_dtype_single$* const $group_dset$)
    @@ -1947,6 +2418,7 @@ The basic (non-suffixed) API call on datasets deals with double precision (see T
     
       if (file  == NULL) return TREXIO_INVALID_ARG_1;
       if ($group_dset$ == NULL) return TREXIO_INVALID_ARG_2;
    +  if (trexio_has_$group_dset$(file) != TREXIO_SUCCESS) return TREXIO_DSET_MISSING;
     
       trexio_exit_code rc;
       int64_t $group_dset_dim$ = 0;
    @@ -2008,6 +2480,7 @@ The basic (non-suffixed) API call on datasets deals with double precision (see T
     
    +
    trexio_exit_code
     trexio_write_$group_dset$_32 (trexio_t* const file, const $group_dset_dtype_single$* $group_dset$)
    @@ -2074,6 +2547,191 @@ The basic (non-suffixed) API call on datasets deals with double precision (see T
     }
     
    +
    +
    + +
    +
    3.3.1.4 Source code for memory-safe functions
    +
    +
    +
    trexio_exit_code rc;
    +int64_t $group_dset_dim$ = 0;
    +
    +/* Error handling for this call is added by the generator */
    +rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$));
    +
    +if ($group_dset_dim$ == 0L) return TREXIO_INVALID_NUM;
    +
    +uint32_t rank = $group_dset_rank$;
    +uint64_t dims[$group_dset_rank$] = {$group_dset_dim_list$};
    +
    +/* The block below is specific to safe API as it checks the boundaries */
    +uint64_t dim_size = 1;
    +for (uint32_t i=0; i<rank; ++i){
    +    dim_size *= dims[i];
    +}
    +
    +
    + + +
    +
    trexio_exit_code
    +trexio_read_safe_$group_dset$_32 (trexio_t* const file, $group_dset_dtype_single$* const dset_out, const int64_t dim_out)
    +{
    +
    +  if (file  == NULL) return TREXIO_INVALID_ARG_1;
    +  if (dset_out == NULL) return TREXIO_INVALID_ARG_2;
    +  if (trexio_has_$group_dset$(file) != TREXIO_SUCCESS) return TREXIO_DSET_MISSING;
    +
    +trexio_exit_code rc;
    +int64_t $group_dset_dim$ = 0;
    +
    +/* Error handling for this call is added by the generator */
    +rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$));
    +
    +if ($group_dset_dim$ == 0L) return TREXIO_INVALID_NUM;
    +
    +uint32_t rank = $group_dset_rank$;
    +uint64_t dims[$group_dset_rank$] = {$group_dset_dim_list$};
    +
    +/* The block below is specific to safe API as it checks the boundaries */
    +uint64_t dim_size = 1;
    +for (uint32_t i=0; i<rank; ++i){
    +    dim_size *= dims[i];
    +}
    +
    +  if (dim_out > (int64_t) dim_size) return TREXIO_UNSAFE_ARRAY_DIM;
    +
    +  return trexio_read_$group_dset$_32(file, dset_out);
    +}
    +
    +
    + + +
    +
    trexio_exit_code
    +trexio_write_safe_$group_dset$_32 (trexio_t* const file, const $group_dset_dtype_single$* dset_in, const int64_t dim_in)
    +{
    +
    +  if (file  == NULL) return TREXIO_INVALID_ARG_1;
    +  if (dset_in == NULL) return TREXIO_INVALID_ARG_2;
    +  if (trexio_has_$group_dset$(file) == TREXIO_SUCCESS) return TREXIO_DSET_ALREADY_EXISTS;
    +
    +trexio_exit_code rc;
    +int64_t $group_dset_dim$ = 0;
    +
    +/* Error handling for this call is added by the generator */
    +rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$));
    +
    +if ($group_dset_dim$ == 0L) return TREXIO_INVALID_NUM;
    +
    +uint32_t rank = $group_dset_rank$;
    +uint64_t dims[$group_dset_rank$] = {$group_dset_dim_list$};
    +
    +/* The block below is specific to safe API as it checks the boundaries */
    +uint64_t dim_size = 1;
    +for (uint32_t i=0; i<rank; ++i){
    +    dim_size *= dims[i];
    +}
    +
    +  if (dim_in > (int64_t) dim_size) return TREXIO_UNSAFE_ARRAY_DIM;
    +
    +  return trexio_write_$group_dset$_32(file, dset_in);
    +}
    +
    +
    + +
    +
    trexio_exit_code
    +trexio_read_safe_$group_dset$_64 (trexio_t* const file, $group_dset_dtype_double$* const dset_out, const int64_t dim_out)
    +{
    +
    +  if (file  == NULL) return TREXIO_INVALID_ARG_1;
    +  if (dset_out == NULL) return TREXIO_INVALID_ARG_2;
    +  if (trexio_has_$group_dset$(file) != TREXIO_SUCCESS) return TREXIO_DSET_MISSING;
    +
    +trexio_exit_code rc;
    +int64_t $group_dset_dim$ = 0;
    +
    +/* Error handling for this call is added by the generator */
    +rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$));
    +
    +if ($group_dset_dim$ == 0L) return TREXIO_INVALID_NUM;
    +
    +uint32_t rank = $group_dset_rank$;
    +uint64_t dims[$group_dset_rank$] = {$group_dset_dim_list$};
    +
    +/* The block below is specific to safe API as it checks the boundaries */
    +uint64_t dim_size = 1;
    +for (uint32_t i=0; i<rank; ++i){
    +    dim_size *= dims[i];
    +}
    +
    +  if (dim_out > (int64_t) dim_size) return TREXIO_UNSAFE_ARRAY_DIM;
    +
    +  return trexio_read_$group_dset$_64(file, dset_out);
    +}
    +
    +
    + + +
    +
    trexio_exit_code
    +trexio_write_safe_$group_dset$_64 (trexio_t* const file, const $group_dset_dtype_double$* dset_in, const int64_t dim_in)
    +{
    +
    +  if (file  == NULL) return TREXIO_INVALID_ARG_1;
    +  if (dset_in == NULL) return TREXIO_INVALID_ARG_2;
    +  if (trexio_has_$group_dset$(file) == TREXIO_SUCCESS) return TREXIO_DSET_ALREADY_EXISTS;
    +
    +trexio_exit_code rc;
    +int64_t $group_dset_dim$ = 0;
    +
    +/* Error handling for this call is added by the generator */
    +rc = trexio_read_$group_dset_dim$_64(file, &($group_dset_dim$));
    +
    +if ($group_dset_dim$ == 0L) return TREXIO_INVALID_NUM;
    +
    +uint32_t rank = $group_dset_rank$;
    +uint64_t dims[$group_dset_rank$] = {$group_dset_dim_list$};
    +
    +/* The block below is specific to safe API as it checks the boundaries */
    +uint64_t dim_size = 1;
    +for (uint32_t i=0; i<rank; ++i){
    +    dim_size *= dims[i];
    +}
    +
    +  if (dim_in > (int64_t) dim_size) return TREXIO_UNSAFE_ARRAY_DIM;
    +
    +  return trexio_write_$group_dset$_64(file, dset_in);
    +}
    +
    +
    +
    +
    + +
    +
    3.3.1.5 Source code for default functions
    +
    +
    +
    trexio_exit_code
    +trexio_read_safe_$group_dset$ (trexio_t* const file, $group_dset_dtype_default$* const $group_dset$, const int64_t dim_out)
    +{
    +  return trexio_read_safe_$group_dset$_$default_prec$(file, $group_dset$, dim_out);
    +}
    +
    +
    + + +
    +
    trexio_exit_code
    +trexio_write_safe_$group_dset$ (trexio_t* const file, const $group_dset_dtype_default$* $group_dset$, const int64_t dim_in)
    +{
    +  return trexio_write_safe_$group_dset$_$default_prec$(file, $group_dset$, dim_in);
    +}
    +
    +
    +
    trexio_exit_code
    @@ -2084,6 +2742,7 @@ The basic (non-suffixed) API call on datasets deals with double precision (see T
     
    +
    trexio_exit_code
     trexio_write_$group_dset$ (trexio_t* const file, const $group_dset_dtype_default$* $group_dset$)
    @@ -2093,6 +2752,7 @@ The basic (non-suffixed) API call on datasets deals with double precision (see T
     
    +
    trexio_exit_code
     trexio_has_$group_dset$ (trexio_t* const file)
    @@ -2123,9 +2783,10 @@ The basic (non-suffixed) API call on datasets deals with double precision (see T
     
    +
    -
    -

    3.3.2 Fortran templates for front end

    +
    +

    3.3.2 Fortran templates for front end

    The Fortran templates that provide an access to the C API calls from Fortran. @@ -2209,10 +2870,205 @@ These templates are based on the use of iso_c_binding. Pointers hav

    + +
    +

    3.3.3 Python templates for front end

    +
    +
    +
    def write_$group_dset$(trexio_file, dset_w) -> None: 
    +    """Write the $group_dset$ array of numbers in the TREXIO file.
    +
    +    Parameters:
    +
    +    trexio_file:
    +        TREXIO File object.
    +
    +    dset_w: list OR numpy.ndarray
    +        Array of $group_dset$ values to be written. If array data type does not correspond to int64 or float64, the conversion is performed.
    +
    +    Raises:
    +        - Exception from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error.
    +        - Exception from some other error (e.g. RuntimeError).
    +    """
    +
    +    try:
    +        import numpy as np
    +    except ImportError:
    +        raise Exception("NumPy cannot be imported.")
    +
    +    doConversion = False
    +    doFlatten = False
    +    if not isinstance(dset_w, (list, tuple)):
    +       # if input array is not a list or tuple then it is probably a numpy array
    +       if isinstance(dset_w, np.ndarray) and (not dset_w.dtype==np.int64 or not dset_w.dtype==np.float64):
    +           doConversion = True
    +
    +       if len(dset_w.shape) > 1:
    +           doFlatten = True
    +           if doConversion:
    +               dset_64 = np.$group_dset_py_dtype$64(dset_w).flatten()
    +           else:
    +               dset_flat = np.array(dset_w, dtype=np.$group_dset_py_dtype$64).flatten()
    +       else:
    +           if doConversion:
    +               dset_64 = np.$group_dset_py_dtype$64(dset_w)
    +
    +    else:
    +       # if input array is a multidimensional list or tuple, we have to convert it
    +       try:
    +           doFlatten = True
    +           ncol = len(dset_w[0])
    +           dset_flat = np.array(dset_w, dtype=np.$group_dset_py_dtype$64).flatten()
    +       except TypeError:
    +           doFlatten = False
    +           pass
    +
    +
    +    if doConversion:
    +        rc = pytr.trexio_write_safe_$group_dset$_64(trexio_file.pytrexio_s, dset_64)
    +    elif doFlatten:
    +        rc = pytr.trexio_write_safe_$group_dset$_64(trexio_file.pytrexio_s, dset_flat)
    +    else:
    +        rc = pytr.trexio_write_safe_$group_dset$_64(trexio_file.pytrexio_s, dset_w)
    +
    +    if rc != TREXIO_SUCCESS:
    +        raise Error(rc)
    +
    -
    -

    3.4 Sparse data structures

    +
    +
    def read_$group_dset$(trexio_file, dim = None, doReshape = None, dtype = None): 
    +    """Read the $group_dset$ array of numbers from the TREXIO file.
    +
    +    Parameters:
    +
    +    trexio_file:
    +        TREXIO File object.
    +
    +    dim (Optional): int
    +        Size of the block to be read from the file (i.e. how many items of $group_dset$ will be returned)
    +        If None, the function will read all necessary array dimensions from the file.
    +
    +    dtype (Optional): type
    +        NumPy data type of the output (e.g. np.int32|int16 or np.float32|float16). If specified, the output array will be converted from the default double precision.
    +
    +    doReshape (Optional): bool
    +        Flag to determine whether the output NumPy array has be reshaped or not. Be default, reshaping is performed
    +        based on the dimensions from the ~trex.json~ file. Otherwise, ~shape~ array (list or tuple) is used if provided by the user.
    +
    +    Returns:
    +        ~dset_64~ if dtype is None or ~dset_converted~ otherwise: numpy.ndarray 
    +        1D NumPy array with ~dim~ elements corresponding to $group_dset$ values read from the TREXIO file.
    +
    +    Raises:
    +        - Exception from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error.
    +        - Exception from some other error (e.g. RuntimeError).
    +"""
    +
    +    try:
    +        import numpy as np
    +    except ImportError:
    +        raise Exception("NumPy cannot be imported.")
    +
    +    if doReshape is None:
    +        doReshape = True
    +
    +    # if dim is not specified, read dimensions from the TREXIO file
    +    dims_list = None
    +    if dim is None or doReshape:
    +        $group_dset_dim$ = read_$group_dset_dim$(trexio_file) 
    +
    +        dims_list = [$group_dset_dim_list$]
    +        dim = 1
    +        for i in range($group_dset_rank$):
    +            dim *= dims_list[i]
    +
    +
    +    shape = tuple(dims_list)
    +    if shape is None and doReshape:
    +        raise ValueError("Reshaping failure: shape is None.")
    +
    +    try:
    +        rc, dset_64 = pytr.trexio_read_safe_$group_dset$_64(trexio_file.pytrexio_s, dim)
    +
    +        if rc != TREXIO_SUCCESS:
    +            raise Error(rc)
    +    except:
    +        raise
    +
    +
    +    isConverted = False
    +    dset_converted = None
    +    if dtype is not None:
    +
    +        try:
    +            assert isinstance(dtype, type)
    +        except AssertionError:
    +            raise TypeError("dtype argument has to be an instance of the type class (e.g. np.float32).")
    +
    +
    +        if not dtype==np.int64 or not dtype==np.float64:
    +            try:
    +                dset_converted = np.array(dset_64, dtype=dtype)
    +            except:
    +                raise
    +
    +            isConverted = True
    +
    +    # additional assert can be added here to check that read_safe functions returns numpy array of proper dimension
    +
    +    if doReshape:
    +        try:
    +            # in-place reshaping did not work so I have to make a copy
    +            if isConverted:    
    +                dset_reshaped = np.reshape(dset_converted, shape, order='C')
    +            else:
    +                dset_reshaped = np.reshape(dset_64, shape, order='C')
    +        except:
    +            raise
    +
    +    if isConverted:    
    +        return dset_converted
    +    elif doReshape:
    +        return dset_reshaped
    +    else:
    +        return dset_64
    +
    +
    + +
    +
    def has_$group_dset$(trexio_file) -> bool: 
    +    """Check that $group_dset$ variable exists in the TREXIO file.
    +
    +    Parameter is a ~TREXIO File~ object that has been created by a call to ~open~ function.
    +
    +    Returns:
    +          True if the variable exists, False otherwise
    +
    +    Raises:
    +        - Exception from trexio.Error class if TREXIO return code ~rc~ is TREXIO_FAILURE and prints the error message using string_of_error.
    +        - Exception from some other error (e.g. RuntimeError).
    +    """
    +
    +    try:
    +        rc = pytr.trexio_has_$group_dset$(trexio_file.pytrexio_s)
    +        if rc == TREXIO_FAILURE:
    +            raise Error(rc)
    +    except:
    +        raise    
    +
    +    if rc == TREXIO_SUCCESS:
    +        return True
    +    else:
    +        return False
    +
    +
    +
    +
    +
    + +
    +

    3.4 Sparse data structures

    Sparse data structures are used typically for large tensors such as @@ -2353,12 +3209,12 @@ For the values,

    -
    -

    3.5 Templates for front end has/read/write a dataset of strings

    +
    +

    3.5 Templates for front end has/read/write a dataset of strings

    -
    -

    3.5.1 Introduction

    +
    +

    3.5.1 Introduction

    This section concerns API calls related to datasets of strings. @@ -2398,8 +3254,8 @@ This section concerns API calls related to datasets of strings.

    -
    -

    3.5.2 C templates for front end

    +
    +

    3.5.2 C templates for front end

    First parameter is the TREXIO file handle. Second parameter is the variable to be written/read @@ -2409,12 +3265,13 @@ to/from the TREXIO file (except for trexio_has_ functi

    trexio_exit_code
    -trexio_read_$group_dset$_low (trexio_t* const file, char* dset, const uint32_t max_str_len)
    +trexio_read_$group_dset$_low (trexio_t* const file, char* dset_out, const int32_t max_str_len)
     {
     
       if (file  == NULL) return TREXIO_INVALID_ARG_1;
    -  if (dset == NULL) return TREXIO_INVALID_ARG_2;
    +  if (dset_out == NULL) return TREXIO_INVALID_ARG_2;
       if (max_str_len <= 0) return TREXIO_INVALID_ARG_3;
    +  if (trexio_has_$group_dset$(file) != TREXIO_SUCCESS) return TREXIO_DSET_MISSING;
     
       trexio_exit_code rc;
       int64_t $group_dset_dim$ = 0;
    @@ -2431,15 +3288,15 @@ to/from the TREXIO file (except for trexio_has_ functi
       switch (file->back_end) {
     
       case TREXIO_TEXT:
    -    return trexio_text_read_$group_dset$(file, dset, rank, dims, max_str_len);
    +    return trexio_text_read_$group_dset$(file, dset_out, rank, dims, (uint32_t) max_str_len);
         break;
     
       case TREXIO_HDF5:
    -    return trexio_hdf5_read_$group_dset$(file, dset, rank, dims, max_str_len);
    +    return trexio_hdf5_read_$group_dset$(file, dset_out, rank, dims, (uint32_t) max_str_len);
         break;
     /*
       case TREXIO_JSON:
    -    rc = trexio_json_read_$group_dset$(file, dset, rank, dims);
    +    rc = trexio_json_read_$group_dset$(file, dset_out, rank, dims);
         break;
     */
       }
    @@ -2448,12 +3305,13 @@ to/from the TREXIO file (except for trexio_has_ functi
     }
     
     trexio_exit_code
    -trexio_read_$group_dset$ (trexio_t* const file, char** dset, const uint32_t max_str_len)
    +trexio_read_$group_dset$ (trexio_t* const file, char** dset_out, const int32_t max_str_len)
     {
     
       if (file  == NULL) return TREXIO_INVALID_ARG_1;
    -  if (dset == NULL) return TREXIO_INVALID_ARG_2;
    +  if (dset_out == NULL) return TREXIO_INVALID_ARG_2;
       if (max_str_len <= 0) return TREXIO_INVALID_ARG_3;
    +  if (trexio_has_$group_dset$(file) != TREXIO_SUCCESS) return TREXIO_DSET_MISSING;
     
       assert(file->back_end < TREXIO_INVALID_BACK_END);
     
    @@ -2474,17 +3332,17 @@ to/from the TREXIO file (except for trexio_has_ functi
         return rc;
       }
     
    -  char * pch;
    -  for (uint64_t i=0; i < dset_dim; i++) {
    +  for (uint64_t i=0; i < (uint64_t) dset_dim; i++) {
     
    +    char * pch;
         pch = i == 0 ? strtok(str_compiled, TREXIO_DELIM) : strtok(NULL, TREXIO_DELIM) ;
         if (pch == NULL) {
           FREE(str_compiled);
           return TREXIO_FAILURE;
         }
     
    -    strcpy(dset[i], "");
    -    strcat(dset[i], pch);
    +    strcpy(dset_out[i], "");
    +    strcat(dset_out[i], pch);
     
       }
     
    @@ -2497,11 +3355,11 @@ to/from the TREXIO file (except for trexio_has_ functi
     
     
    trexio_exit_code
    -trexio_write_$group_dset$_low (trexio_t* const file, const char* dset, const uint32_t max_str_len)
    +trexio_write_$group_dset$_low (trexio_t* const file, const char* dset_in, const int32_t max_str_len)
     {
     
       if (file  == NULL) return TREXIO_INVALID_ARG_1;
    -  if (dset == NULL) return TREXIO_INVALID_ARG_2;
    +  if (dset_in == NULL) return TREXIO_INVALID_ARG_2;
       if (max_str_len <= 0) return TREXIO_INVALID_ARG_3;
       if (trexio_has_$group_dset$(file) == TREXIO_SUCCESS) return TREXIO_DSET_ALREADY_EXISTS;
     
    @@ -2521,14 +3379,16 @@ to/from the TREXIO file (except for trexio_has_ functi
       char*  tmp_str  = CALLOC(dims[0]*(max_str_len+1), char);
       if (tmp_str == NULL) return TREXIO_ALLOCATION_FAILED;
       char** dset_str = CALLOC(dims[0], char*);
    -  if (dset_str == NULL) return TREXIO_ALLOCATION_FAILED;
    +  if (dset_str == NULL) {
    +    FREE(tmp_str);
    +    return TREXIO_ALLOCATION_FAILED;
    +  }
     
    -  char* pch;
    -  size_t pch_len;
       /* parse the string using strtok */
       for(uint64_t i=0; i<dims[0]; i++) {
     
    -    pch = i == 0 ? strtok( (char*) dset, TREXIO_DELIM) : strtok(NULL, TREXIO_DELIM) ;
    +    char* pch;
    +    pch = i == 0 ? strtok( (char*) dset_in, TREXIO_DELIM) : strtok(NULL, TREXIO_DELIM) ;
     
         if (pch == NULL) {
           FREE(dset_str[0]);
    @@ -2536,9 +3396,9 @@ to/from the TREXIO file (except for trexio_has_ functi
           return TREXIO_FAILURE;
         }
     
    -    pch_len = strlen(pch);
    +    size_t pch_len = strlen(pch) + 1;
     
    -    if (pch_len > max_str_len) {
    +    if (pch_len > (size_t) max_str_len) {
           FREE(dset_str[0]);
           FREE(dset_str);
           return TREXIO_INVALID_STR_LEN;
    @@ -2574,11 +3434,11 @@ to/from the TREXIO file (except for trexio_has_ functi
     }
     
     trexio_exit_code
    -trexio_write_$group_dset$ (trexio_t* const file, const char** dset, const uint32_t max_str_len)
    +trexio_write_$group_dset$ (trexio_t* const file, const char** dset_in, const int32_t max_str_len)
     {
     
       if (file  == NULL) return TREXIO_INVALID_ARG_1;
    -  if (dset == NULL) return TREXIO_INVALID_ARG_2;
    +  if (dset_in == NULL) return TREXIO_INVALID_ARG_2;
       if (max_str_len <= 0) return TREXIO_INVALID_ARG_3;
       if (trexio_has_$group_dset$(file) == TREXIO_SUCCESS) return TREXIO_DSET_ALREADY_EXISTS;
     
    @@ -2596,8 +3456,8 @@ to/from the TREXIO file (except for trexio_has_ functi
       if (str_compiled == NULL) return TREXIO_ALLOCATION_FAILED;
     
       strcpy(str_compiled, "");
    -  for (uint64_t i=0; i < dset_dim; i++) {
    -    strcat(str_compiled, dset[i]);
    +  for (uint64_t i=0; i < (uint64_t) dset_dim; i++) {
    +    strcat(str_compiled, dset_in[i]);
         strcat(str_compiled, TREXIO_DELIM);
       }
     
    @@ -2642,8 +3502,8 @@ to/from the TREXIO file (except for trexio_has_ functi
     
    -
    -

    3.5.3 Fortran templates for front end

    +
    +

    3.5.3 Fortran templates for front end

    The Fortran templates that provide an access to the C API calls from Fortran. @@ -2738,14 +3598,130 @@ These templates are based on the use of iso_c_binding. Pointers hav

    + +
    +

    3.5.4 Python templates for front end

    +
    +
    +
    def write_$group_dset$(trexio_file, dset_w: list) -> None: 
    +    """Write the $group_dset$ array of strings in the TREXIO file.
    +
    +    Parameters:
    +
    +    trexio_file:
    +        TREXIO File object.
    +
    +    dset_w: list
    +        Array of $group_dset$ strings to be written.
    +
    +    Raises:
    +        - Exception from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error.
    +        - Exception from some other error (e.g. RuntimeError).
    +    """
    +
    +    max_str_length = len(max(dset_w, key=len)) + 1
    +
    +    try:
    +        rc = pytr.trexio_write_$group_dset$(trexio_file.pytrexio_s, dset_w, max_str_length)
    +
    +        if rc != TREXIO_SUCCESS:
    +            raise Error(rc)
    +    except:
    +        raise    
    +
    +
    -
    -

    3.6 Templates for front end has/read/write a single string attribute

    +
    +
    def read_$group_dset$(trexio_file, dim = None) -> list: 
    +    """Read the $group_dset$ array of strings from the TREXIO file.
    +
    +    Parameters:
    +
    +    trexio_file:
    +        TREXIO File object.
    +
    +    dim (Optional): int
    +        Size of the block to be read from the file (i.e. how many items of $group_dset$ will be returned)
    +        If None, the function will read all necessary array dimensions from the file.
    +
    +    Returns:
    +        ~dset_r~: list
    +        1D list with ~dim~ elements corresponding to $group_dset$ strings read from the TREXIO file.
    +
    +    Raises:
    +        - Exception from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error.
    +        - Exception from some other error (e.g. RuntimeError).
    +    """
    +
    +    # if dim is not specified, read dimensions from the TREXIO file
    +    if dim is None:
    +        $group_dset_dim$ = read_$group_dset_dim$(trexio_file) 
    +
    +        dims_list = [$group_dset_dim_list$]
    +        dim = 1
    +        for i in range($group_dset_rank$):
    +            dim *= dims_list[i]
    +
    +
    +    try:
    +        rc, dset_1d_r = pytr.trexio_read_$group_dset$_low(trexio_file.pytrexio_s, PYTREXIO_MAX_STR_LENGTH)
    +
    +        if rc != TREXIO_SUCCESS:
    +            raise Error(rc)
    +    except:
    +        raise    
    +
    +
    +    try:
    +        dset_full = dset_1d_r.split(pytr.TREXIO_DELIM)
    +        dset_2d_r = [dset_full[i] for i in range(dim) if dset_full[i]]
    +        if not dset_2d_r:
    +            raise ValueError(f"Output of {read_$group_dset$.__name__} function cannot be an empty list.")
    +    except:
    +        raise
    +
    +    return dset_2d_r
    +
    +
    + +
    +
    def has_$group_dset$(trexio_file) -> bool: 
    +    """Check that $group_dset$ variable exists in the TREXIO file.
    +
    +    Parameter is a ~TREXIO File~ object that has been created by a call to ~open~ function.
    +
    +    Returns:
    +          True if the variable exists, False otherwise
    +
    +    Raises:
    +        - Exception from trexio.Error class if TREXIO return code ~rc~ is TREXIO_FAILURE and prints the error message using string_of_error.
    +        - Exception from some other error (e.g. RuntimeError).
    +    """
    +
    +    try:
    +        rc = pytr.trexio_has_$group_dset$(trexio_file.pytrexio_s)
    +        if rc == TREXIO_FAILURE:
    +            raise Error(rc)
    +    except:
    +        raise    
    +
    +    if rc == TREXIO_SUCCESS:
    +        return True
    +    else:
    +        return False
    +
    +
    +
    +
    +
    + +
    +

    3.6 Templates for front end has/read/write a single string attribute

    -
    -

    3.6.1 Introduction

    +
    +

    3.6.1 Introduction

    This section concerns API calls related to string attributes. @@ -2785,28 +3761,27 @@ This section concerns API calls related to string attributes.

    -
    -

    3.6.2 C templates for front end

    +
    +

    3.6.2 C templates for front end

    trexio_exit_code
    -trexio_read_$group_str$ (trexio_t* const file, char* const str, const uint32_t max_str_len)
    +trexio_read_$group_str$ (trexio_t* const file, char* const str_out, const int32_t max_str_len)
     {
     
       if (file == NULL) return TREXIO_INVALID_ARG_1;
    -  if (str  == NULL) return TREXIO_INVALID_ARG_2;
    +  if (str_out  == NULL) return TREXIO_INVALID_ARG_2;
       if (max_str_len <= 0) return TREXIO_INVALID_ARG_3;
    -
    -  trexio_exit_code rc = TREXIO_FAILURE;
    +  if (trexio_has_$group_str$(file) != TREXIO_SUCCESS) return TREXIO_ATTR_MISSING;
     
       switch (file->back_end) {
     
       case TREXIO_TEXT:
    -    return trexio_text_read_$group_str$(file, str, max_str_len);
    +    return trexio_text_read_$group_str$(file, str_out, (uint32_t) max_str_len);
         break;
     
       case TREXIO_HDF5:
    -    return trexio_hdf5_read_$group_str$(file, str, max_str_len);
    +    return trexio_hdf5_read_$group_str$(file, str_out, (uint32_t) max_str_len);
         break;
     /*
       case TREXIO_JSON:
    @@ -2822,7 +3797,7 @@ This section concerns API calls related to string attributes.
     
     
    trexio_exit_code
    -trexio_write_$group_str$ (trexio_t* const file, const char* str, const uint32_t max_str_len)
    +trexio_write_$group_str$ (trexio_t* const file, const char* str, const int32_t max_str_len)
     {
     
       if (file == NULL) return TREXIO_INVALID_ARG_1;
    @@ -2831,7 +3806,7 @@ This section concerns API calls related to string attributes.
       if (trexio_has_$group_str$(file) == TREXIO_SUCCESS) return TREXIO_ATTR_ALREADY_EXISTS;
     
       size_t len_write = strlen(str);
    -  if (max_str_len < len_write) return TREXIO_INVALID_STR_LEN;  
    +  if ((size_t) max_str_len < len_write) return TREXIO_INVALID_STR_LEN;  
     
       switch (file->back_end) {
     
    @@ -2886,8 +3861,8 @@ This section concerns API calls related to string attributes.
     
    -
    -

    3.6.3 Fortran templates for front end

    +
    +

    3.6.3 Fortran templates for front end

    The Fortran templates that provide an access to the C API calls from Fortran. @@ -2963,11 +3938,100 @@ These templates are based on the use of iso_c_binding. Pointers hav

    + +
    +

    3.6.4 Python templates for front end

    +
    +
    +
    def write_$group_str$(trexio_file, str_w: str) -> None: 
    +    """Write the $group_str$ variable in the TREXIO file.
    +
    +    Parameters:
    +
    +    trexio_file:
    +        TREXIO File object.
    +
    +    str_w: str
    +        String corresponding to the $group_str$ variable to be written.
    +
    +    Raises:
    +        - Exception from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error.
    +        - Exception from some other error (e.g. RuntimeError).
    +    """
    +
    +    max_str_length = len(str_w) + 1
    +
    +    try:
    +        rc = pytr.trexio_write_$group_str$(trexio_file.pytrexio_s, str_w, max_str_length)
    +
    +        if rc != TREXIO_SUCCESS:
    +            raise Error(rc)
    +    except:
    +        raise    
    +
    +
    + +
    +
    def read_$group_str$(trexio_file) -> str: 
    +    """Read the $group_str$ variable from the TREXIO file.
    +
    +    Parameter is a ~TREXIO File~ object that has been created by a call to ~open~ function.
    +
    +    Returns:
    +        ~str_r~: str
    +        String corresponding to the $group_str$ variable read from ~trexio_file~.
    +
    +    Raises:
    +        - Exception from AssertionError if TREXIO return code ~rc~ is different from TREXIO_SUCCESS and prints the error message using trexio_string_of_error.
    +        - Exception from some other error (e.g. RuntimeError).
    +    """
    +
    +    try:
    +        rc, str_r = pytr.trexio_read_$group_str$(trexio_file.pytrexio_s, PYTREXIO_MAX_STR_LENGTH)
    +
    +        if rc != TREXIO_SUCCESS:
    +            raise Error(rc)
    +    except:
    +        raise    
    +
    +    return str_r
    +
    +
    + +
    +
    def has_$group_str$(trexio_file) -> bool: 
    +    """Check that $group_str$ variable exists in the TREXIO file.
    +
    +    Parameter is a ~TREXIO File~ object that has been created by a call to ~open~ function.
    +
    +    Returns:
    +          True if the variable exists, False otherwise
    +
    +    Raises:
    +        - Exception from trexio.Error class if TREXIO return code ~rc~ is TREXIO_FAILURE and prints the error message using string_of_error.
    +        - Exception from some other error (e.g. RuntimeError).
    +    """
    +
    +    try:
    +        rc = pytr.trexio_has_$group_str$(trexio_file.pytrexio_s)
    +        if rc == TREXIO_FAILURE:
    +            raise Error(rc)
    +    except:
    +        raise    
    +
    +    if rc == TREXIO_SUCCESS:
    +        return True
    +    else:
    +        return False
    +
    +
    +
    +
    -
    -

    4 Fortran helper/wrapper functions

    +
    +

    4 Fortran helper/wrapper functions

    The function below adapts the original C-based trexio_open for Fortran. @@ -3101,7 +4165,7 @@ two code are identical, i.e. if the assert statement pass.

    Author: TREX-CoE

    -

    Created: 2021-09-13 Mon 16:10

    +

    Created: 2021-09-14 Tue 09:40

    Validate

    diff --git a/templator_hdf5.html b/templator_hdf5.html index a3a8a11..f634681 100644 --- a/templator_hdf5.html +++ b/templator_hdf5.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + HDF5 back end @@ -311,27 +311,27 @@ for the JavaScript code in this tag.

    Table of Contents

    -
    -

    1 HDF5 back end

    +
    +

    1 HDF5 back end

    -
    -

    1.1 Template for HDF5 definitions

    +
    +

    1.1 Template for HDF5 definitions

    #define $GROUP$_GROUP_NAME          "$group$"
    @@ -343,15 +343,14 @@ for the JavaScript code in this tag.
     
    -
    -

    1.2 Template for HDF5 structures

    +
    +

    1.2 Template for HDF5 structures

    typedef struct trexio_hdf5_s {
       trexio_t     parent ;
    -  hid_t      file_id;
    -  hid_t      $group$_group;
    -  const char* file_name;
    +  hid_t        file_id;
    +  hid_t        $group$_group;
     } trexio_hdf5_t;
     
    @@ -359,8 +358,8 @@ for the JavaScript code in this tag.
    -
    -

    1.3 Template for HDF5 init/deinit

    +
    +

    1.3 Template for HDF5 init/deinit

    trexio_exit_code
    @@ -440,8 +439,8 @@ for the JavaScript code in this tag.
     
    -
    -

    1.4 Template for HDF5 has/read/write a single dimensioning variable

    +
    +

    1.4 Template for HDF5 has/read/write a single dimensioning variable

    trexio_exit_code
    @@ -557,8 +556,8 @@ for the JavaScript code in this tag.
     
    -
    -

    1.5 Template for HDF5 has/read/write a dataset of numerical data

    +
    +

    1.5 Template for HDF5 has/read/write a dataset of numerical data

    trexio_exit_code
    @@ -687,8 +686,8 @@ for the JavaScript code in this tag.
     
    -
    -

    1.6 Template for HDF5 has/read/write a dataset of strings

    +
    +

    1.6 Template for HDF5 has/read/write a dataset of strings

    trexio_exit_code
    @@ -819,15 +818,22 @@ for the JavaScript code in this tag.
     
       /* we are going to write variable-length strings */
       hid_t memtype = H5Tcopy (H5T_C_S1);
    +  if (memtype <= 0) return TREXIO_INVALID_ID;
    +
       status = H5Tset_size (memtype, H5T_VARIABLE);
    +  if (status < 0) return TREXIO_FAILURE;
     
       if ( H5LTfind_dataset(f->$group$_group, $GROUP_DSET$_NAME) != 1 ) {
     
         /* code to create dataset */   
         hid_t filetype = H5Tcopy (H5T_FORTRAN_S1);
    +    if (filetype <= 0) return TREXIO_INVALID_ID;
    +
         status = H5Tset_size (filetype, H5T_VARIABLE);
    +    if (status < 0) return TREXIO_FAILURE;
     
         hid_t dspace = H5Screate_simple( (int) rank, (const hsize_t*) dims, NULL);
    +    if (dspace <= 0) return TREXIO_INVALID_ID;
     
         dset_id = H5Dcreate (f->$group$_group, $GROUP_DSET$_NAME, filetype, dspace,
                              H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
    @@ -892,8 +898,8 @@ for the JavaScript code in this tag.
     
    -
    -

    1.7 Template for HDF5 has/read/write a single string attribute

    +
    +

    1.7 Template for HDF5 has/read/write a single string attribute

    trexio_exit_code
    @@ -1020,7 +1026,7 @@ for the JavaScript code in this tag.
     

    Author: TREX-CoE

    -

    Created: 2021-09-13 Mon 16:10

    +

    Created: 2021-09-14 Tue 09:40

    Validate

    diff --git a/templator_text.html b/templator_text.html index a59bdc3..f16e9bf 100644 --- a/templator_text.html +++ b/templator_text.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + TEXT back end @@ -311,26 +311,26 @@ for the JavaScript code in this tag.

    Table of Contents

    -
    -

    1 TEXT back end

    +
    +

    1 TEXT back end

    The "file" produced by the text back end is a directory with one @@ -361,8 +361,8 @@ The file is written when closed, or when the flush function is called.

    -
    -

    1.1 Template for group-related structures in text back end

    +
    +

    1.1 Template for group-related structures in text back end

    typedef struct $group$_s {
    @@ -380,8 +380,8 @@ The file is written when closed, or when the flush function is called.
     
    -
    -

    1.2 Template for general structure in text back end

    +
    +

    1.2 Template for general structure in text back end

    typedef struct rdm_s {
    @@ -407,8 +407,8 @@ The file is written when closed, or when the flush function is called.
     
    -
    -

    1.3 Initialize function (constant part)

    +
    +

    1.3 Initialize function (constant part)

    trexio_exit_code
    @@ -509,8 +509,8 @@ The file is written when closed, or when the flush function is called.
     
    -
    -

    1.4 Deinitialize function (templated part)

    +
    +

    1.4 Deinitialize function (templated part)

    trexio_exit_code
    @@ -535,8 +535,8 @@ The file is written when closed, or when the flush function is called.
     
    -
    -

    1.5 Template for text read struct

    +
    +

    1.5 Template for text read struct

    $group$_t*
    @@ -743,8 +743,6 @@ trexio_text_read_$group$ (trexio_text_t* END REPEAT GROUP_DSET_NUM
     
    -    size_t tmp_len;
    -
         // START REPEAT GROUP_DSET_STR
         /* Allocate arrays */
         $group$->$group_dset$ = CALLOC(size_$group_dset$, $group_dset_dtype$);
    @@ -772,7 +770,7 @@ trexio_text_read_$group$ (trexio_text_t*     */
         char* tmp_$group_dset$;
         if(size_$group_dset$ != 0) tmp_$group_dset$ = CALLOC(size_$group_dset$*32, char);
    -    tmp_len = 0;
    +
         for (uint64_t i=0 ; i<size_$group_dset$ ; ++i) {
           $group$->$group_dset$[i] = tmp_$group_dset$;
           /* conventional fcanf with "%s" only return the string before the first space character 
    @@ -788,8 +786,8 @@ trexio_text_read_$group$ (trexio_text_t* return NULL;
           }
     
    -      tmp_len = strlen($group$->$group_dset$[i]);
    -      tmp_$group_dset$ += tmp_len + 1;
    +      size_t tmp_$group_dset$_len = strlen($group$->$group_dset$[i]);
    +      tmp_$group_dset$ += tmp_$group_dset$_len + 1;
         }
         // END REPEAT GROUP_DSET_STR
     
    @@ -807,8 +805,8 @@ trexio_text_read_$group$ (trexio_text_t* 
     
    -
    -

    1.6 Template for text flush struct

    +
    +

    1.6 Template for text flush struct

    trexio_exit_code
    @@ -872,8 +870,8 @@ trexio_text_read_$group$ (trexio_text_t* 
     
    -
    -

    1.7 Template for text free memory

    +
    +

    1.7 Template for text free memory

    Memory is allocated when reading. The following function frees memory. @@ -918,8 +916,8 @@ Memory is allocated when reading. The following function frees memory.

    -
    -

    1.8 Template for has/read/write the num attribute

    +
    +

    1.8 Template for has/read/write the num attribute

    trexio_exit_code
    @@ -981,8 +979,8 @@ Memory is allocated when reading. The following function frees memory.
     
    -
    -

    1.9 Template for has/read/write the dataset of numerical data

    +
    +

    1.9 Template for has/read/write the dataset of numerical data

    The group_dset array is assumed allocated with the appropriate size. @@ -1078,8 +1076,8 @@ The group_dset array is assumed allocated with the appropriate size

    -
    -

    1.10 Template for has/read/write the dataset of strings

    +
    +

    1.10 Template for has/read/write the dataset of strings

    The group_dset array is assumed allocated with the appropriate size. @@ -1144,9 +1142,8 @@ The group_dset array is assumed allocated with the appropriate size char* tmp_str = CALLOC(dims[0]*32 + 1, char); if (tmp_str == NULL) return TREXIO_ALLOCATION_FAILED; - size_t tmp_len = 0; for (uint64_t i=0 ; i<dims[0] ; ++i) { - tmp_len = strlen(dset[i]); + size_t tmp_len = strlen(dset[i]); $group$->$group_dset$[i] = tmp_str; strncpy(tmp_str, dset[i], tmp_len); tmp_str += tmp_len + 1; @@ -1181,8 +1178,8 @@ The group_dset array is assumed allocated with the appropriate size

    -
    -

    1.11 Template for has/read/write the string attribute

    +
    +

    1.11 Template for has/read/write the string attribute

    trexio_exit_code
    @@ -1256,12 +1253,12 @@ The group_dset array is assumed allocated with the appropriate size
     
    -
    -

    1.12 RDM struct (hard-coded)

    +
    +

    1.12 RDM struct (hard-coded)

    -
    -

    1.12.1 Read the complete struct

    +
    +

    1.12.1 Read the complete struct

    rdm_t* trexio_text_read_rdm(trexio_text_t* const file);
    @@ -1356,8 +1353,8 @@ The group_dset array is assumed allocated with the appropriate size
     
    -
    -

    1.12.2 Flush the complete struct

    +
    +

    1.12.2 Flush the complete struct

    trexio_exit_code trexio_text_flush_rdm(trexio_text_t* const file);
    @@ -1399,8 +1396,8 @@ The group_dset array is assumed allocated with the appropriate size
     
    -
    -

    1.12.3 Free memory

    +
    +

    1.12.3 Free memory

    Memory is allocated when reading. The followig function frees memory. @@ -1436,8 +1433,8 @@ Memory is allocated when reading. The followig function frees memory.

    -
    -

    1.12.4 Read/Write the onee attribute

    +
    +

    1.12.4 Read/Write the onee attribute

    The one_e array is assumed allocated with the appropriate size. @@ -1503,8 +1500,8 @@ The one_e array is assumed allocated with the appropriate size.

    -
    -

    1.12.5 Read/Write the twoe attribute

    +
    +

    1.12.5 Read/Write the twoe attribute

    two_e is a sparse data structure, which can be too large to fit @@ -1612,7 +1609,7 @@ file for each sparse float structure.

    Author: TREX-CoE

    -

    Created: 2021-09-13 Mon 16:10

    +

    Created: 2021-09-14 Tue 09:40

    Validate

    diff --git a/trex.html b/trex.html index 9619062..fd90e94 100644 --- a/trex.html +++ b/trex.html @@ -3,7 +3,7 @@ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> - + TREX Configuration file @@ -333,28 +333,28 @@ for the JavaScript code in this tag.

    Table of Contents

    @@ -386,8 +386,8 @@ arrays are 0-based. Hence, we introduce the index type which is an 1-based int in the Fortran interface and 0-based otherwise.

    -
    -

    1 Metadata (metadata group)

    +
    +

    1 Metadata (metadata group)

    As we expect our files to be archived in open-data repositories, we @@ -397,7 +397,7 @@ which have participated to the creation of the file, a list of authors of the file, and a textual description.

    - +
    @@ -464,15 +464,15 @@ authors of the file, and a textual description. -
    -

    2 Electron (electron group)

    +
    +

    2 Electron (electron group)

    We consider wave functions expressed in the spin-free formalism, where the number of ↑ and ↓ electrons is fixed.

    -
    +
    @@ -511,15 +511,15 @@ the number of ↑ and ↓ electrons is fixed. -
    -

    3 Nucleus (nucleus group)

    +
    +

    3 Nucleus (nucleus group)

    The nuclei are considered as fixed point charges. Coordinates are given in Cartesian \((x,y,z)\) format.

    -
    +
    @@ -579,8 +579,8 @@ given in Cartesian \((x,y,z)\) format. -
    -

    4 TODO Effective core potentials (ecp group)

    +
    +

    4 TODO Effective core potentials (ecp group)

    An effective core potential (ECP) \(V_A^{\text{pp}}\) replacing the @@ -625,7 +625,7 @@ letters are parameters.

  • \(\hat{V}_\text{ecp,nl} = \sum_A \hat{V}_A^{\text{nl}}\) : non-local component
  • -
    +
    @@ -734,8 +734,8 @@ letters are parameters. -
    -

    5 Basis set (basis group)

    +
    +

    5 Basis set (basis group)

    We consider here basis functions centered on nuclei. Hence, we enable @@ -788,7 +788,7 @@ If the the basis function is not considered normalized, \(\mathcal{N}_s=1\). All the basis set parameters are stored in one-dimensional arrays:

    -
    +
    @@ -957,8 +957,8 @@ prim_factor = -
    -

    6 Atomic orbitals (ao group)

    +
    +

    6 Atomic orbitals (ao group)

    Going from the atomic basis set to AOs implies a systematic @@ -1006,13 +1006,13 @@ shell, as in the GAMESS convention where

    In such a case, one should set the normalization of the shell (in -the Basis set section) to \(\mathcal{N}_{z^2}\), which is the +the Basis set section) to \(\mathcal{N}_{z^2}\), which is the normalization factor of the atomic orbitals in spherical coordinates. The normalization factor of the \(xy\) function which should be introduced here should be \(\frac{\mathcal{N}_{xy}}{\mathcal{N}_{z^2}}\).

    -
    +
    @@ -1064,8 +1064,8 @@ introduced here should be \(\frac{\mathcal{N}_{xy}}{\mathcal{N}_{z^2}}\).
    -
    -

    6.1 One-electron integrals (ao_1e_int group)

    +
    +

    6.1 One-electron integrals (ao_1e_int group)

    • \[ \hat{V}_{\text{ne}} = \sum_{A=1}^{N_\text{nucl}} @@ -1083,7 +1083,7 @@ The one-electron integrals for a one-electron operator \(\hat{O}\) are over atomic orbitals.

      - +
      @@ -1150,8 +1150,8 @@ over atomic orbitals. -
      -

      6.2 Two-electron integrals (ao_2e_int group)

      +
      +

      6.2 Two-electron integrals (ao_2e_int group)

      The two-electron integrals for a two-electron operator \(\hat{O}\) are @@ -1172,7 +1172,7 @@ notation. \mathbf{r}_j \vert)}{\vert \mathbf{r}_i - \mathbf{r}_j \vert} \] : electron-electron long range potential -

      +
      @@ -1212,10 +1212,10 @@ notation. -
      -

      7 Molecular orbitals (mo group)

      +
      +

      7 Molecular orbitals (mo group)

      -
      +
      @@ -1281,8 +1281,8 @@ notation.
    -
    -

    7.1 One-electron integrals (mo_1e_int group)

    +
    +

    7.1 One-electron integrals (mo_1e_int group)

    The operators as the same as those defined in the @@ -1290,7 +1290,7 @@ The operators as the same as those defined in the the basis of molecular orbitals.

    - +
    @@ -1357,8 +1357,8 @@ the basis of molecular orbitals. -
    -

    7.2 Two-electron integrals (mo_2e_int group)

    +
    +

    7.2 Two-electron integrals (mo_2e_int group)

    The operators as the same as those defined in the @@ -1366,7 +1366,7 @@ The operators as the same as those defined in the the basis of molecular orbitals.

    -
    +
    @@ -1406,13 +1406,13 @@ the basis of molecular orbitals. -
    -

    8 TODO Slater determinants

    +
    +

    8 TODO Slater determinants

    -
    -

    9 TODO Reduced density matrices (rdm group)

    +
    +

    9 TODO Reduced density matrices (rdm group)

    -
    +
    @@ -1465,15 +1465,15 @@ the basis of molecular orbitals. -
    -

    10 Appendix

    +
    +

    10 Appendix

    -
    -

    10.1 Python script from table to json

    +
    +

    10.1 Python script from table to json

    -
    print("""#+begin_src python :tangle trex.json""")
    +
    print("""#+begin_src python :tangle trex.json""")
     print("""    "%s": {"""%(title))
     indent = "        "
     f1 = 0 ; f2 = 0 ; f3 = 0
    @@ -1526,7 +1526,7 @@ the basis of molecular orbitals.
     

    Author: TREX-CoE

    -

    Created: 2021-09-13 Mon 16:10

    +

    Created: 2021-09-14 Tue 09:40

    Validate