...
...
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 IDS via UAL.
Warning |
---|
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! <- |
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 IDS from UAL
- know how to access IDS data
Exercise no. 3 (approx. 15 min)
1. source ITMv1 script by invoking
source $ITMSCRIPTDIR/ITMv1 kepler test 4.10b > /dev/null
2. Go to example directory
cd $TUTORIAL_DIR/ids_basics/python/
3. Execute sample code
Code Block |
---|
|
shell> python ./put_ids_array.py
shell> python ./put_ids_slices.py |
4. Open example file
Handling IDSes: put() vs. putSlice() |
---|
Code Block |
---|
language | py |
---|
title | $TUTORIAL_DIR/ids_basics/python/put_ids_array.py |
---|
linenumbers | true |
---|
| import sys
from pylab import *
import ual
ids = ual.itm(13,3)
ids.create()
if not ids.isConnected():
print 'error during itmdb entry creation'
sys.exit(1)
ids.equilibriumArray.resize(10)
equi = ids.equilibriumArray
#First fill fields which are not time-dependent.
equi.array[0].datainfo.dataprovider = 'MKO'
equi.array[0].datainfo.putdate = '20/09/2016'
equi.array[0].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
ids.close() |
| Code Block |
---|
language | py |
---|
title | $TUTORIAL_DIR/ids_basics/python/put_ids_slices.py |
---|
linenumbers | true |
---|
| import sys
from pylab import *
import ual
ids = ual.itm(14,4)
ids.create()
if not ids.isConnected():
print 'error during itmdb entry creation'
sys.exit(1)
equi = ids.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
ids.close() |
|
...
3.2.1 Changes
CHEAT SHEET |
ITM | IMAS |
---|
use euitm_schemas | use ids_schemas |
use euitm_routines | use ids_routines |
type (type_<cpo_name>) :: cpo | type (ids_<ids_name>) :: ids |
type (type_<cpo_name>), pointer :: cpoArray(:) ! <= Array !!! | type (ids_<ids_name>) :: ids <== SINGLE OBJ !!! |
call euitm_create('euitm', shot, run, refShot, refRun, idx) | call imas_create('ids', shot, run, refShot, refRun, idx) |
call euitm_open('euitm', shot, run, idx) | call imas_open('ids', shot, run, idx) |
call euitm_put(idx, '<cpo_name>', cpoArray) <== ARRAY! | call ids_put(idx, '<ids_name>', ids) <== SINGLE OBJ |
call euitm_put_non_timed(idx,"<cpo_name>", cpo) | call ids_put_non_timed(idx,"<ids_name>",ids) |
call euitm_put_slice(idx, '<cpo_name>', cpo) | call ids_put_slice(idx, '<ids_name>', ids) |
call euitm_deallocate(cpoArray) | call ids_deallocate(ids) |
call euitm_close(idx) | call imas_close(idx) |
call euitm_enable_mem_cache(idx) | call imas_enable_mem_cache(idx) |
call euitm_disable_mem_cache(idx) | call imas_disable_mem_cache(idx) |
call euitm_flush_all(idx) | call imas_flush_all(idx) |
3.2.2 CPO/IDS put
put() CPO vs IDS |
---|
Code Block |
---|
| program diagnostic
use euitm_schemas
use euitm_routines
implicit none
integer :: idx, i, arraySize
type (type_equilibrium), pointer::cpoArray(:)<= ARRAY!
! Open a database
call euitm_create('euitm', 11, 22, -1, -1, idx)
! CPO structure allocation
allocate(cpoArray(10))
!SCALARS (!)
do i=1, 10
cpoArray(i)%time = VALUE
cpoArray(i)%x%y = VALUE
enddo
call euitm_put(idx, 'equilibrium', cpoArray)
call euitm_deallocate(cpoArray)
! Close a pulse file
call euitm_close(idx)
end program |
| Code Block |
---|
| program diagnostic
use ids_schemas
use ids_routines
implicit none
integer :: idx, i
type (ids_core_profiles): ids <= Single object !!
! Open a database
call imas_create('ids', 11, 22, -1, -1, idx)
! Mandatory to define this property
ids%ids_properties%homogeneous_time = 1
! IDS structure allocation
allocate(ids%time(10))
allocate(ids%x%y(10))
!SCALARS (!)
do i=1, 10
ids%time(i) = VALUE
ids%x%y(i) = VALUE
enddo
! VECTORS
ids%time = timeVector
ids%x%y = valueVector
call ids_put(idx, 'core_profiles', ids)
call ids_deallocate(ids)
! Close a pulse file
call imas_close(idx)
end program
|
|
3.2.3 CPO/IDS putSlice
putSlice() CPO vs IDS |
---|
Code Block |
---|
| program diagnostic
use euitm_schemas
use euitm_routines
implicit none
integer :: idx, i
type (type_equilibrium) :: cpo ! <= Single object !!!
! Open a database
call euitm_create('euitm', 11, 22, -1, -1, idx)
! Time NOT dependent data
allocate(cpo%datainfo%dataprovider(1))
cpo%datainfo%dataprovider="FI"
call euitm_put_non_timed(idx, 'equilibrium', cpo)
cpo%time = VALUE
cpo%x%y = VALUE
call euitm_put_slice(idx, 'equilibrium', cpo)
call euitm_deallocate(cpoArray)
! Close a pulse file
call euitm_close(idx)
end program |
| Code Block |
---|
| program diagnostic
use ids_schemas
use ids_routines
implicit none
integer :: idx, i
type (ids_core_profiles) :: ids ! <= Single object !
! Open a database
call imas_create('ids', 11, 22, -1, -1, idx)
! Mandatory to define this property
ids%ids_properties%homogeneous_time = 1
! Time NOT dependent data
allocate(ids%ids_properties%comment(1))
ids%ids_properties%comment(1) = 'IDS put by put_slice'
call ids_put_non_timed(idx,"core_profiles",ids)
! IDS structure allocation
allocate(ids%time(1))
allocate(ids%x%y(1))
ids%time(1) = VALUE
ids%x%y(1) = VALUE
call ids_put_slice(idx, 'core_profiles', ids)
call ids_deallocate(ids)
! Close a pulse file
call imas_close(idx)
end program
|
|
3.2.4 CPO/IDS get
vi $TUTORIAL_DIR/ids_basics/python/put_ids.py
What you can see here is a simple code that stores particular IDS into MDSPlus database using UAL.
Let's check how to read these data in Fortran.
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 IDS 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/ids_basics/fortran
...
get() CPO vs IDS |
---|
Code Block |
---|
title | $TUTORIAL_DIR/ids_basics/fortran/get_ids_array.f90ITM |
---|
linenumbers | true |
---|
| program diagnostic
use euitm_schemas
use euitm_routines
implicit none
integer :: idx, i, arraySize
type (type_equilibrium), pointer :: eqArraycpoArray(:) ! <= Array !!!
! Open a database
call euitm_open('IDSeuitm', 14, 4, idx)
! Get data
call euitm_get(idx, 'equilibrium', eqArraycpoArray)
! Check array size
arraySize = size(eqArraycpoArray)
! write (*,*) "Number of slices: ", arraySize<= array of CPOs
! SCALARS (!)
do i=1, arraySize
write (*,*) "Time : ", eqArraycpoArray(i)%time
write (*,*) "Value of r: ", eqArraycpoArray(i)%eqgeometry%boundary(1)%r(1)%x%y
enddo
write (*,*) "Value of z: ", eqArray(i)%eqgeometry%boundary(1)%z(1)
enddo
! Close a pulse file
call call euitm_close(idx)
end prograprogram |
| Code Block |
---|
title | $TUTORIAL_DIR/ids_basics/fortran/get_ids_slices.f90IMAS |
---|
linenumbers | true |
---|
| program diagnostic
use imasids_schemas
use imasids_routines
implicit none
integer :: idx, i, arraySize
type (typeids_core_equilibriumprofiles), pointer :: eqArray(:)ids ! <= Single Arrayobject !!!
! Open a database
call imas_open('IDSids', 14, 4, idx)
! Get data
call imasids_get(idx, 'equilibriumcore_profiles', eqArrayids)
! Check array size
arraySize arraySize = size(eqArrayids%time)
! <= time write (*,*) "Number of slices: ", arraySize
vector
! SCALARS (!)
do i=1, arraySize
write (*,*) "Time : ", eqArrayids%time(i)%time
write (*,*) "Value of r: ", eqArrayids%x%y(i)%eqgeometry%boundary(1)%r(1)
enddo
! VECTORS
write (*,*) "ValueTime of z: ", eqArray(i)%eqgeometry%boundary(1)%z(1)
enddoids%time
write (*,*) "Value: ", ids%x%y
! Close a pulse file
call call imas_close(idx)
end program |
|
...
3.2.5 CPO/IDS getSlice
getSlice() CPO vs IDS |
---|
Code Block |
---|
language | cpp |
---|
title | ITM |
---|
linenumbers | true |
---|
| program diagnostic
! UAL library
use euitm_schemas
use euitm_routines
implicit none
integer :: idx
type (type_equilibrium) :: cpo
! Open a database
call euitm_open('euitm', 11, 4, idx)
! Get data
call euitm_get_slice(idx, 'equilibrium', cpo, 4.0, 1)
write (*,*) "Time : ", cpo%time
write (*,*) "Value : ", cpo%x%y
! Memory clean-up
call euitm_deallocate(ids)cpo)
! Close a pulse file
call euitm_close(idx)
end program |
| Code Block |
---|
| program diagnostic
! UAL library
use ids_schemas
use ids_routines
implicit none
integer :: idx
type (ids_core_profiles) :: ids
! Open a database
call imas_open('ids', 11, 22, idx)
! Get data
call ids_get_slice(idx, 'core_profiles', ids, 4.0, 1)
write (*,*) "Time : ", ids%time
write (*,*) "Value : ", ids%x%y
! Memory clean-up
call ids_deallocate(ids)
call imas_close(idx)
end program |
|
4. Compile the code
Code Block |
---|
shell> make clean
shell> make |
5. Run the code
Code Block |
---|
shell> ./get_ids_array.exe
shell> ./get_ids_slices.exe |
6. You should see values that we have stored using Python based code.
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:
- Prepare Fortran code that has a subroutine to be called and is compiled as a library
- Prepare FC2K based description of the actor
- 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
...
! Close a pulse file
call imas_close(idx)
end program |
|