Prepare your environment:

$ module load imasenv/3.24.0/rc
$ mkdir -p $ITMWORK/projects
$ cd $ITMWORK/projects
$ cp -r $SWIMASDIR/resources/tutorials/2019-10-PSNC/fc2k-testing-framework .

Before proceeding any further, make sure you have configured your Kepler environment. Take a look here 00. Initial setup or here 05.3. IMAS - basic topics - environment set-up(POZ'19Oct)

The structure of your working directory should look like this:

$ cd fc2k-testing-framework/primitives_param/fortran/
$ tree
.
├── clean.sh
├── Makefile
├── primitives_param.f90			# FC2K actor with accessing code parameters
├── primitivesparam_fc2k.xml		# FC2K configuration file
├── primitivesparam_workflow.xml	# example workflow  
├── run_test.sh						# script for run example
├── sample_default.xml
├── sample.xml						# XML file with parameters
└── sample.xsd						# defining the structure of an XML document

Let's see what the xml file looks like with the parameters.
Suppose we want to download an "i" parameter from this file.

sample.xml
<?xml version="1.0"?>
<parameters>
  <r> 3.141592 </r>
  <i> 2 </i> 
  <boolean> True False </boolean>
  <realVec> 2.7e2  4.0 </realVec>
  <intVec> 13 7 </intVec>
  <booleanVec> True False </booleanVec>
</parameters>

Below is an example of the code that retrieves parameters/i value from an xml file:

primitives_param.f90
subroutine primitivesparam(in_input, out_output, user_in_codeparamstruct)

  use ids_schemas, only: ids_real, ids_int, ids_equilibrium, ids_core_profiles, ids_parameters_input
  use xml2eg_mdl, only: xml2eg_parse_memory, xml2eg_get, type_xml2eg_document, xml2eg_free_doc, set_verbose
  use iso_c_binding, only: c_int

  implicit none

  integer, intent(in)        :: in_input
  integer, intent(out)       :: out_output
  integer(ids_int)           :: value_int
  integer(c_int)             :: tmp_value_int

  type(ids_parameters_input) :: user_in_codeparamstruct
  type(type_xml2eg_document) :: doc

  ! Parse the "codeparam_string". This means that the data is put into a document "doc"
  call xml2eg_parse_memory( user_in_codeparamstruct%parameters_value, doc )
  call set_verbose(.TRUE.)

  ! Extract data in "doc" at position "parameters/i" and store it in "int_value"
  call xml2eg_get( doc , 'i' , tmp_value_int)

  value_int  = int( tmp_value_int, ids_int )

  ! Make sure to clean up after you!!
  ! When calling "xml2eg_parse_memory" memory was allocated in the "doc" object.
  ! This memory is freed by "xml2eg_free_doc(doc)"
  call xml2eg_free_doc(doc)

  out_output = in_input + value_int

  return

end subroutine

Run an example:

$ module load imasenv/3.24.0/rc		# load environment if not set
$ ./run_test.sh
Compilation - OK
Skipping log removal
FC2K build for primitives with params - OK
Skipping log removal
Workflow execution: primitives with params - OK
Skipping log removal
Checking output - should be equal to '3' - OK
Skipping log removal

Investigate test.log file to find more detailed information on this example.


  • No labels