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/code_parameters .
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 code_parameters $ tree . ├── input_test_xmllib_pathquery.xml ├── input_test_xmllib_pathquery.xsd ├── Makefile # instructions on how to compile ├── sample_default.xml ├── sample.f90 # code with accessing code parameters ├── sample.xml # file with parameters └── sample.xsd # defining the structure of an XML document
A sample xml file containing information in the form of parameters for an actor:
sample.xml
<?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="./ets.xsl" charset="ISO-8859-1"?> <parameters> <input> <shot_in> 4 </shot_in> <!-- shot number --> <run_in> 1 </run_in> <!-- run number --> <interpol> 1 </interpol> <!-- interpolation index --> <time_dep_input> 0 </time_dep_input> <!-- 1 implies time dependence in input data --> </input> <output> <shot_out> 5 </shot_out> <!-- shot number --> <run_out> 2 </run_out> <!-- run number --> <tau_out> 0.0003 </tau_out> <!-- output frequency --> <db_out> mdsplus </db_out> <!-- output database format --> </output> <dims> <nrho> 50 </nrho> <!-- NRHO, number of radial points --> <npsi> 100 </npsi> <!-- NPSI, number of equilibrium points --> <neq_dim1> 100 </neq_dim1> <!-- NDIM1, number of points for 2-D equilibrium signals in R direction --> <neq_dim2> 100 </neq_dim2> <!-- NDIM2, number of points for 2-D equilibrium signals in Z direction --> <neq_max_npoints> 100 </neq_max_npoints> <!-- MAX_NPOINTS, number of equilibrium boundary points --> </dims> ... <experimental> <option> -1 </option> <!-- option #: 0: disabled --> </experimental> </parameters>
The first 35 lines of this code show how you can handle reading of the xml file in which the actor's parameters are saved:
sample.f90
!> Test program Christian Konz version of xmllib. program sample use xml_file_reader, only: fill_param use xml2eg_mdl use xmllib_parser, only: element, tree, xmllib_parse, destroy_xml_tree use string_manipulation_tools implicit none ! Input parameters, read from file character(132), pointer :: param_xml(:) => NULL() character(132), pointer :: param_xsd(:) => NULL() character(132), pointer :: param_default(:) => NULL() ! Input file names: character(132) :: fn_xml = 'sample.xml' character(132) :: fn_xml_default = 'sample.xml' character(132) :: fn_xsd = 'sample.xsd' ! Representation of xml parameters TYPE(tree) :: parameter_list TYPE(element), POINTER :: temp_pointer => null() character(len = 132) :: cname ! Values parser from xml integer :: shot_in, run_in integer(4) :: nparm real(8) :: geo_ax call fill_param(param_xml, param_default, param_xsd, fn_xml, fn_xml_default, fn_xsd) CALL XMLLIB_PARSE(param_xml, param_xsd, param_default, nparm, parameter_list) temp_pointer => parameter_list%first outer: do write(*,*)'Next xml element: ',temp_pointer%cname cname = char2str(temp_pointer%cname) ! necessary for AIX !write(0,*)'RFOF_input::RFOF_parse_xml_input_param, cname=',trim(cname) select case (cname) ... end select do if (associated(temp_pointer%sibling)) then temp_pointer => temp_pointer%sibling exit end if if (associated(temp_pointer%parent, parameter_list%first )) & exit outer if (associated(temp_pointer%parent)) then temp_pointer => temp_pointer%parent else write(0, *) 'ERROR: broken list.' stop end if end do end do outer !-- destroy tree call destroy_xml_tree(parameter_list) end program sample
Run an example:
$ module load imasenv/3.24.0/rc # load environment if not set $ make ifort -fPIC -g -I/gw/swimas/extra/xmllib/3.2.0/intel/17.0/include/xmllib -I/usr/include/libxml2 -c -o sample.o sample.f90 ifort -fPIC -g -o sample.exe sample.o -L/gw/swimas/extra/xmllib/3.2.0/intel/17.0/lib -lxmllib -lxml2 ./sample.exe Next xml element: parameters Next xml element: input Next xml element: shot_in Read shot_in= 4 Next xml element: run_in Read shot_in= 1 Next xml element: interpol Next xml element: time_dep_input Next xml element: output Next xml element: dims Next xml element: compositions Next xml element: startup Next xml element: boundary Next xml element: equilibrium Next xml element: geo_ax Read geo_ax= 2.86000000000000 Next xml element: plasma_ax Next xml element: amin Next xml element: elong Next xml element: tria_up Next xml element: tria_low Next xml element: solver Next xml element: experimental
Compare result with data inside sample.xml file.