You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

 

 

In this tutorial

  • how can you integrate your code with UAL
  • how can you access data via UAL

Accessing data from UAL requires some modification to your code. In this part of tutorial, we will take a closer look on how to access CPO via UAL.

 

 

Warning

Stop here for a moment. Make sure you have followed the configuration setup before proceeding any further!

Configuration related tutorial is here -> Click me! <-

 

1.1.1. 3.1 Accessing data using Python

Exercise no. 3 - After this exercise you will:

  • know how to access UAL using Python
  • know how to retrieve CPO from UAL
  • know how to access CPO data

Exercise no. 3 (approx. 15 min)

In this exercise you will browse MDSPlus database using jTraverser application.

1. source ITMv1 script by invoking

source $ITMSCRIPTDIR/ITMv1 kepler test 4.10b > /dev/null

2. Go to example directory

cd $TUTORIAL_DIR/cpo_basics/python/

3. Execute sample code

python put_cpo.py

4. Open example file

Handling CPOs: put() vs. putSlice()
$TUTORIAL_DIR/cpo_basics/python/put_cpo_array.py
import sys
from pylab import * 
import ual

cpo = ual.itm(13,3)
cpo.create()

if not cpo.isConnected():
    print 'error during itmdb entry creation'
    sys.exit(1)

cpo.equilibriumArray.resize(100)
equi = cpo.equilibriumArray

for i in range(0, 10):
    #Time independent fields
    equi.array[i].datainfo.dataprovider = 'MKO'
    equi.array[i].datainfo.putdate = '20/09/2016'
    equi.array[i].codeparam.parameters = 'param'
    equi.array[i].eqgeometry.boundary.resize(1)
    equi.array[i].eqgeometry.boundary[0].r = sin(arange(0,2*pi,2*pi/100)) + (1/float(100-i))
    equi.array[i].eqgeometry.boundary[0].z = cos(arange(0,2*pi,2*pi/100)) + (1/float(100-i))
    
#Do not forget time!!
    equi.array[i].time = i

equi.put()

#close the pulse file
cpo.close()
$TUTORIAL_DIR/cpo_basics/python/put_cpo_slices.py
import sys
from pylab import * 
import ual

cpo = ual.itm(14,4)
cpo.create()

if not cpo.isConnected():
    print 'error during itmdb entry creation'
    sys.exit(1)

equi = cpo.equilibrium

#First fill fields which are not time-dependent.
equi.datainfo.dataprovider = 'MKO'
equi.datainfo.putdate = '20/09/2016'
equi.codeparam.parameters = 'param'

#Save time independent fields
equi.putNonTimed()

for i in range(0, 10):
    equi.eqgeometry.boundary.resize(1)
    equi.eqgeometry.boundary[0].r = sin(arange(0,2*pi,2*pi/100)) + (1/float(100-i))
    equi.eqgeometry.boundary[0].z = cos(arange(0,2*pi,2*pi/100)) + (1/float(100-i))
    
    #Do not forget time!!
    equi.time = i 
    
    #Append this slice in the database
    equi.putSlice()

#close the pulse file
cpo.close()
VI related notice
I will use VI in every place where text files are modified. If you have any other text file editor of your choice - fell free to use it instead.

 

vi $TUTORIAL_DIR/cpo_basics/python/put_cpo.py

What you can see here is a simple code that stores particular CPO into MDSPlus database using UAL.

 

 

Let's check how to read these data in Fortran.

1.1.2. 3.2 Accessing data using Fortran

Exercise no. 4 - After this exercise you will:

  • know how to connect to UAL
  • know how to retrieve data from UAL
  • know how to prepare Makefile for your Fortran code

Exercise no. 4 (approx. 15 min)

In this exercise you will read CPO and print some data stored inside.

1. source ITMv1 script by invoking

source $ITMSCRIPTDIR/ITMv1 kepler test 4.10b > /dev/null

2. Change directory to a demo location for this exercise

cd $TUTORIAL_DIR/cpo_basics/fortran

3. Open GetSlice.f90 file

vi GetSlice.f90

4. You should see code similar to following one


 
program diagnostic
    use euitm_schemas
    use euitm_routines
    use write_structures
    implicit none

    integer :: idx
    type (type_equilibrium), pointer :: equilibrium(:)

    Integer x

    call euitm_open('euitm', 12, 2, idx)

    call euitm_get(idx, 'equilibrium', equilibrium)

    write (*,*) "Size of CPO: ", size(equilibrium)

    write (*,*) "Value of r: ", equilibrium(1)%eqgeometry%boundary(1)%r(1)
    write (*,*) "Value of z: ", equilibrium(1)%eqgeometry%boundary(1)%z(1)

    call euitm_close(idx)
    call euitm_disconnect()
end program

 

5. Run the code

make clean
make
./readEquilibrium

 

 

6. You should see values that we have stored using Python based code.

1.2. 4. FC2K - Fortran Code to Kepler

It is possible to encapsulate Fortran/C++ code with Java code that represents Kepler actor. This way, you can easily incorporate your Fortran code with existing Kepler workflow. In order to make it happen you will have to:

  1. Prepare Fortran code that has a subroutine to be called and is compiled as a library
  2. Prepare FC2K based description of the actor
  3. Recompile Kepler with newly created actor

After these steps are performed, you will have an access to Kepler actor that encapsulates your Fortran code.

All these topics will be covered in separate tutorial: 1.4 Using FC2K for embedding Fortran code into Kepler

  • No labels