Versions Compared

Key

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

...

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

Code Block
languagebash
shell> python ./put_cpo_array.py
shell> python ./put_cpo_slices.py

 

 

4. Open example file

Handling CPOs: put() vs. putSlice()
Code Block
languagepy
title$TUTORIAL_DIR/cpo_basics/python/put_cpo_array.py
linenumberstrue
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(10010)
equi = cpo.equilibriumArray

for#First ifill in range(0, 10):
    #Time independent fields
    fields which are not time-dependent.
equi.array[i0].datainfo.dataprovider = 'MKO'
    equi.array[i0].datainfo.putdate = '20/09/2016'
    equi.array[i0].codeparam.parameters = 'param'



# ---- a loop ----
for i in range(0, 10):
    #Fill time-dependent fields 
    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
# ---- a loop ----

#Save data in the database
equi.put() # <= Called outside the loop

#close the pulse file
cpo.close()
Code Block
languagepy
title$TUTORIAL_DIR/cpo_basics/python/put_cpo_slices.py
linenumberstrue
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()
# ---- a loop ----
for i in range(0, 10):
	#Fill time-dependent fields  
	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() # <= Called inside the loop
# ---- a loop ----

#close the pulse file
cpo.close()

...

cd $TUTORIAL_DIR/cpo_basics/fortran

3. Open GetSlice.f90 file

vi GetSlice.f90

4. You should see code similar to following one

...


 
Handling CPOs: get() vs. getSlice()
Code Block
title$TUTORIAL_DIR/cpo_basics/fortran/get_cpo_array.f90
linenumberstrue

...

program diagnostic
    use euitm_schemas
    use euitm_routines

...

   

...

 

...

implicit none

    integer :: idx, i, arraySize
    type (type_equilibrium), pointer :: 

...

eqArray(:)

...

 ! <= 

...

Array !!!



    call euitm_open('euitm', 

...

14, 

...

4, idx)
    
    call euitm_get(idx, 'equilibrium', 

...

eqArray)
    arraySize = size(eqArray)
    write (*,*) "

...

Number of

...

 slices: ", arraySize
    
	do i=1, arraySize
    	write (*,*) "Time: ", 

...

eqArray(

...

i)%time

...

        write (*,*) "Value of r: ", 

...

eqArray(

...

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

...

eqArray(

...

i)%eqgeometry%boundary(1)%z(1)
    enddo
    call euitm_close(idx)
end program
Code Block
title$TUTORIAL_DIR/cpo_basics/fortran/get_cpo_slices.f90
linenumberstrue
program diagnostic
    use 

...

euitm_schemas
    use euitm_routines  
    implicit none

    integer :: idx, i, arraySize 
    type (type_equilibrium) :: equilibrium
    real(EUITM_R8), pointer :: timeVector(:)
    real(EUITM_R8) :: time

    call euitm_open('euitm', 14, 4, idx)
    
    call euitm_get_times(idx, 'equilibrium',timeVector)
    
    arraySize = size(timeVector)
    write (*,*) "Number of slices: ", arraySize
    write (*,*) "Time vector: ", timeVector
    
	do i = 1, arraySize
        time = timeVector(i)
        call euitm_get_slice(idx, 'equilibrium', equilibrium, time, 1)
            
    	write (*,*) "Time [", time, "]: ",  equilibrium%time
        write (*,*) "Value of r: ", equilibrium%eqgeometry%boundary(1)%r(1)
        write (*,*) "Value of z: ", equilibrium%eqgeometry%boundary(1)%z(1)
    enddo
    
	call euitm_close(idx)
end program

 5

4.

...

 Compile the code
 
Code Block
shell> make clean
shell> make

5. Run the code

Code Block
shell> ./get_cpo_array.exe
shell> ./readEquilibriumget_cpo_slices.exe

 

 

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

...

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