Commit 97db3e16 authored by Robert Izzard's avatar Robert Izzard
Browse files

sync readme

parent 5365d9b1
Loading
Loading
Loading
Loading
+26 −22
Original line number Diff line number Diff line
@@ -40,7 +40,7 @@ Many thanks to the authors of those amazing codes!

------------------------------------------------------------

[[_TOC_]]
{:toc}

------------------------------------------------------------

@@ -90,9 +90,9 @@ Please install *gawk* (`brew install gawk`) and *timeout* (`brew install coreuti

------------------------------------------------------------

# libcdict Usage Instructions : C
# libcdict Instructions : C

## 0. Cdict headers
## 0. C libcdict headers

Include the cdict header file in your C source code.

@@ -100,7 +100,7 @@ Include the cdict header file in your C source code.
    #include <cdict/cdict.h>
```

## 1. Make a new cdict struct
## 1. New cdict struct

To make a cdict called `c`, use:

@@ -114,7 +114,9 @@ You can also make a new cdict with another cdict as its "parent". The child cdic
CDict_new(new_cdict,parent_cdict);
```

## 2. Free the memory associated with a cdict struct, and any nested cdict structs,
## 2. Free cdict struct

Free the memory associated with a cdict struct, and any nested cdict structs,

- If you just want to free the cdict `c` and any associated metadata (if set)

@@ -137,7 +139,7 @@ where the function should expect a `struct cdict_entry_t *` to be passed to it c

Please note: if a `cdict` is freed which is pointed to as the ancestor of another `cdict` this will probaly cause an error. You should thus free cdicts in the reverse order they are accessed, or just free the ancestor (which will free its children).

## 3. Setting scalars, arrays and pointers, including other cdicts, in your cdict, with implicit type guessing.
## 3. Setting scalars, arrays and pointers, including other cdicts, in your cdict, with implicit type guessing

You can set entries containing scalars, pointers and arrays into the cdict with the `CDict_set()` function. This implicitly guesses the types of the key and value you try to set as well as array sizes.

@@ -201,7 +203,7 @@ You can use a four-argument version of `CDict_set()` to give a reference a funct
               free_metadata_function);
```

## 4. Setting scalars and pointers, and arrays, in your cdict, with explicit types.
## 4. Setting scalars, arrays and pointers, including other cdicts, in your cdict, with explicit types

You can set scalars, pointers and arrays in the cdict with the functions `CDict_set_with_types(cdict,key,keytype,value,valuetype)` and `CDict_set_with_types_and_metadata(cdict,key,keytype,value,valuetype,metadata,metadata_free_function)`. These are different to `CDict_set()` in that they do not guess the data's C type, instead you must set this manually.

@@ -980,30 +982,32 @@ data = keys_to_floats(data)
print('keys converted to floats:',data.keys())
```

# Fortran
# libcdict instructions: Fortran

The Fortran module for libcdict is a set of Fortran interfaces that directly call the C API.
It supports the same general functionality defined above with a few limitations, namely:

* The maximum allowed nesting depth is 2 levels.
* Variable types must be defined using iso_c_binding and are currently limited to:
* integer(c_int)
* real(c_float)
* real(c_double)
* character(kind=c_char)
* type(c_ptr)
  * `integer(c_int)`
  * `real(c_float)`
  * `real(c_double)`
  * `character(kind=c_char)`
  * `type(c_ptr)`

The module requires Fortran 90 or higher to use iso_c_binding.

The following functions are currently supported in the Fortran API:
1. CDict_new
2. CDict_copy
3. CDict_set
4. CDict_nest
5. CDict_stats
6. CDict_print_JSON
7. CDict_free

Most of the above documentation is applicable to the Fortran API for these methods, so please read that first. The following is a brief summary of how to call the Fortran subroutines and a short example of a complete program that uses libcdict in Fortran.

1. `CDict_new`
2. `CDict_copy`
3. `CDict_set`
4. `CDict_nest`
5. `CDict_stats`
6. `CDict_print_JSON`
7. `CDict_free`

Most of the above C documentation is applicable to the Fortran API for these methods, so please read that first for details. The following is a brief summary of how to call the Fortran subroutines and a short example of a complete program that uses libcdict in Fortran.

## 0. Fortran cdict module