Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

A new tool written in C has been developed to convert manage Jorek namelist parameters files exported from Fortran to using HDF5 files.

The tool has been presented in May 2022 to the Jorek team at the Max Planck Institute.

...

View file
nameFleury_Jorek_namelist_converter_final.pptxpdf
height250


Compiling and using the tool from the command line

...

The tool can be currently executed from the command line. Soon, it will be integrated to the Jorek fortran program code in order to be called for from Jorek in different use-cases.

...


COMPILING THE SOURCES

...

Code Block
$ cd jorek/util/nmlist2h5

...



Requirements:

...


HDF5 version >= 1.12

...



To use the provided Makefile, be sure that:

...


- The HDF5_HOME environment variable is defined in order to find the HDF5 header files

...


- The HDF5 lib directory is referenced by the LD_LIBRARY_PATH variable, for linking

...


- BOOST library is available in your system

...



Compiling:

...


$ make -f Makefile_namelist

...



Example:

...


[nmlist2h5]$ make -f Makefile_namelist

...


gcc -c -o namelist2h5.o namelist2h5.c

...


gcc -c -o h5_2_namelist.o h5_2_namelist.c

...


gcc -c -o h5_utils.o h5_utils.c

...


gcc -c -o namelist_api.o namelist_api.c

...


g++ -pthread -Wl,--no-undefined -o namelist_api namelist2h5.o h5_2_namelist.o h5_utils.o namelist_api.o -L/Applications/libraries/hdf5/1.12.0/gcc/6.4.0/lib -lhdf5

 API

...

Code Block
Namelist to HDF5 Converter API:

...


//---------------------------------------------------------------------

...


int new_simulation(const char* h5_namelist_folder, const char* nml_file_name);

...


int restart(const char* h5_namelist_folder, const char* nml_file_name, const char* jorek_restart_file_name, const char* time_index);

...


int write_restart_file (const char* h5_namelist_folder, const char* jorek_restart_file);

...


int extract_from_h5_namelist (const char* h5_namelist_folder, const char* nml_file, const char* time_index);

...


int extract_from_jorek_restart_file (const char* h5_namelist_folder, const char* jorek_restart_file_name, const char* nml_file_name, const char* time_index);

...


//---------------------------------------------------------------------

...




NEW SIMULATION:

...



int new_simulation(const char* h5_namelist_folder, const char* nml_file_name);

...



/** Creates a new HDF5 namelist file from an existing JOREK parameters file in CSV format. Parameters are written in the '00000' HDF5 group which will be created.

...


* Inputs:

...


* h5_namelist_folder (string) : directory path in which the new HDF5 namelist file will be created

...


* nml_file_name (string) : name of the JOREK namelist file in CSV format, the file must be supplied in the 'h5_namelist_folder', an error will occur otherwise.

...


* Returns:

...


* 0 if the operation is successfull or a code status < 0 otherwise.

...


**/

...




RESTART:

...



int restart(const char* h5_namelist_folder, const char* nml_file_name, const char* jorek_restart_file_name, const char* time_index);

...



/** If the HDF5 namelist file already exists in the folder specified by 'h5_namelist_folder', 'restart' will update this file from the specified JOREK restart file 'jorek_restart_file_name':

...


* - all HDF5 groups YYYYY >= time_index=XXXXX are removed from the HDF5 namelist file

...


* - the parameters from the file 'nml_file_name' (in CSV format) are added to the HDF5 namelist file in the HDF5 group XXXXX

...


* If the HDF5 namelist does not exist in the folder specified by 'h5_namelist_folder', 'restart' will create a new HDF5 namelist file in the folder 'h5_namelist_folder':

...


* - all parameters of the JOREK restart file specified by 'jorek_restart_file_name' are added to the HDF5 namelist file

...


* - the parameters located in the file 'nml_file_name' (in CSV format) are added to the HDF5 namelist file in the HDF5 group time_index=XXXXX

...


* Inputs:

...


* h5_namelist_folder (string) : directory path in which the HDF5 file is located. If the file does not exist, it will be created in this directory.

...


* nml_file_name (string) : name of the JOREK parameters file in CSV format, the file must be supplied in the 'h5_namelist_folder', an error will occur otherwise.

...


* jorek_restart_file_name (string) : name of the JOREK restart file in HDF5 format, the file must be supplied in the 'h5_namelist_folder' if the HDF5 namelist file does not exist, an error will occur otherwise.

...


* time_index (string) : name of the HDF5 group of the HDF5 namelist file where the namelist parameters from the file 'nml_file_name' will be added

...


* Returns:

...


* 0 if the operation is successfull or a code status < 0 otherwise.

...


**/

...




WRITE RESTART FILE:

...



/** Creates a new HDF5 JOREK restart file. All parameters from the existing HDF5 namelist file are written in the 'namelist' HDF5 group.

...


* If the HDF5 namelist file does not exist in the specified 'h5_namelist_folder' directory, an error will occur.

...


* Inputs:

...


* h5_namelist_folder (string) : directory path in which the new HDF5 JOREK restart file will be created

...


* jorek_restart_file_name (string) : name of the JOREK restart file in HDF5 format

...


* Returns:

...


* 0 if the operation is successfull or a code status < 0 otherwise.

...


**/

...



EXTRACT FROM H5 NAMELIST:

...



/** Creates a new namelist parameters file in CSV format. All parameters from the supplied HDF5 namelist file are extracted from the HDF5 group 'time_index' and copied to the CSV namelist parameters file.

...


* Inputs:

...


* h5_namelist_folder (string) : directory path in which the CSV namelist file will be created. This directory should contain the supplied HDF5 namelist file, an error will occur otherwise.

...


* nml_file_name (string) : name of the CSV namelist file to be created

...


* time_index (string) : time index with format 'XXXXX'

...


* Returns:

...


* 0 if the operation is successfull or a code status < 0 otherwise.

...


**/

...



EXTRACT FROM JOREK RESTART FILE:

...



/** Creates a new namelist parameters file in CSV format. All parameters from the existing JOREK HDF5 restart file are extracted from the HDF5 group 'namelist/time_index' and copied to the CSV namelist file.

...


* Inputs:

...


* h5_namelist_folder (string) : directory path in which the CSV namelist file will be created. This directory should contain the supplied HDF5 namelist file, an error will occur otherwise.

...


* jorek_restart_file_name (string) : name of the JOREK restart file

...


* nml_file_name (string) : name of the CSV namelist file to be created

...


* time_index (string) : time index with format 'XXXXX'

...


* Returns:

...


* 0 if the operation is successfull or a code status < 0 otherwise.

...


**/

...

EXAMPLES

Code Block
NEW SIMULATION

...



./namelist_api new_simulation /Home/LF218007/jorek out711.nml

...


analysing file, 13453 line(s) found with identifier, (n_line=15864)

...


File analysis ended.

...


Number of identifiers=13453.

...


Number of parameters=301.

...


HDF5 dataset for parameter GRID_TO_WALL already previously defined, ignoring new definition

...


HDF5 dataset for parameter FIX_AXIS_NODES already previously defined, ignoring new definition

...




Checking the file with h5dump:

...



h5dump namelist.h5 |less

...



HDF5 "namelist.h5" {

...


GROUP "/" {

...


GROUP "00000" {

...


DATASET "ADAPTIVE_TIME" {

...


DATATYPE H5T_STRING {

...


STRSIZE H5T_VARIABLE;

...


STRPAD H5T_STR_NULLTERM;

...


CSET H5T_CSET_ASCII;

...


CTYPE H5T_C_S1;

...


}

...


DATASPACE SCALAR

...


DATA {

...


(0): "F

...


"

...


}

...


}

...


DATASET "AKI_NEO_CONST" {

...


...




RESTART

./namelist_api restart /Home/LF218007/jorek out711.nml jorek_restart.h5 00001

...


copying time index: 00001...

...


analysing file, 13453 line(s) found with identifier, (n_line=15864)

...


File analysis ended.

...


Number of identifiers=13453.

...


Number of parameters=301.

...


HDF5 dataset for parameter GRID_TO_WALL already previously defined, ignoring new definition

...


HDF5 dataset for parameter FIX_AXIS_NODES already previously defined, ignoring new definition

...



Checking the file with h5ls:

...



$ h5ls namelist.h5

...


00000 Group

...


00001 Group

...




WRITE RESTART FILE:

...



./namelist_api write_restart_file /Home/LF218007/jorek/jorek_repo/jorek/util jorek_restart.h5

...




Checking the file with h5ls:

...



h5ls -r jorek_restart.h5

...



/ Group

...


/namelist Group

...


/namelist/00000 Group

...


/namelist/00000/ADAPTIVE_TIME Dataset {SCALAR}

...


/namelist/00000/AKI_NEO_CONST Dataset {SCALAR}

...


/namelist/00000/AMIN Dataset {SCALAR}

...


/namelist/00000/AMIX Dataset {SCALAR}

...


...

...


/namelist/00001 Group

...


/namelist/00001/ADAPTIVE_TIME Dataset {SCALAR}

...


/namelist/00001/AKI_NEO_CONST Dataset {SCALAR}

...


/namelist/00001/AMIN Dataset {SCALAR}

...


/namelist/00001/AMIX Dataset {SCALAR}

...


...

...


/namelist/00001/Z_LIMITER Dataset {1000/Inf}

...




EXTRACT FROM H5 NAMELIST:

...



./namelist_api extract_from_h5_namelist /Home/LF218007/jorek test.nml 00001

...


found group 00001

...


matched group 00001

...


Converting HDF5 file /Home/LF218007/jorek/jorek_repo/jorek/util/namelist.h5 ...

...




more test.nml

...



&IN1

...


ADAPTIVE_TIME = F

...


,

...


AKI_NEO_CONST = 0.000000e+00,

...


AMIN = 1.000000e+00,

...


AMIX = 0.000000e+00,

...


AMIX_FREEB = 8.500000e-01,

...


AMU_NEO_CONST = 0.000000e+00,

...


AUTODISTRIBUTE_MODES = T

...


,

...


...




EXTRACT FROM JOREK RESTART FILE:

...



./namelist_api extract_from_jorek_restart_file /Home/LF218007/jorek jorek_restart.h5 test2.nml 00001

...


found group 00001

...


matched group 00001

...


Converting HDF5 file /Home/LF218007/jorek/jorek_repo/jorek/util/jorek_restart.h5 ...

...




more test2.nml

...



&IN1

...


ADAPTIVE_TIME = F

...


,

...


AKI_NEO_CONST = 0.000000e+00,

...


AMIN = 1.000000e+00,

...


AMIX = 0.000000e+00,

...


AMIX_FREEB = 8.500000e-01,

...


AMU_NEO_CONST = 0.000000e+00,

...


AUTODISTRIBUTE_MODES = T

...


,

...