3.2.1 Changes
Info |
---|
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! <- |
...
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:: cpo ! cpoArray(:)<= Single object !!!ARRAY!
! Open a database
call euitm_create('euitm', 11, 22, -1, -1, idx)
! CPO structure allocation
allocate(cpoArray(10))
!SCALARS (!)
do i=1, 10
cpo%timecpoArray(i)%time = VALUE
cpo%x%ycpoArray(i)%x%y = VALUE
enddo
call euitm_put_slice(idx, 'equilibrium', cpocpoArray)
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
allocate(ids%ids_properties%comment(1))
ids%ids_properties%comment(1) = 'A test ids put using put_slice'
call ids_put_non_timed(idx,"core_profiles",ids)
! IDS structure allocation
allocate(ids%time(110))
allocate(ids%x%y(110))
!SCALARS (!)
do i=1, 10
ids%time(1i) = VALUE
ids%x%y(1i) = VALUE
enddo
! VECTORS
ids%time = timeVector
ids%x%y = valueVector
call ids_put_slice(idx, 'core_profiles', ids)
call ids_deallocate(ids)
! Close a pulse file
call imas_close(idx)
end program
|
|
...
3.2.3 CPO/IDS putSlice
4. Open example file
putSlice() CPO vs IDS |
---|
Code Block |
---|
| program diagnostic
use euitm_schemas
use euitm_routines
implicit none
integer :: idx, i, arraySize
type (type_equilibrium), pointer :: cpoArray(:)cpo ! <= ArraySingle object !!!
! Open a database
call euitm_create('euitm', 11, 22, -1, -1, idx)
! CPOTime NOT structuredependent allocationdata
allocate(cpoArraycpo%datainfo%dataprovider(101))
!SCALARS (!)
do i=1, 10
cpoArray(i)%time cpo%datainfo%dataprovider="FI"
call euitm_put_non_timed(idx, 'equilibrium', cpo)
cpo%time = VALUE
cpoArray(i)%x%y cpo%x%y = VALUE
enddo
call euitm_put_slice(idx, 'equilibrium', cpoArraycpo)
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
! IDSTime NOT structuredependent allocationdata
allocate(ids%timeids%ids_properties%comment(1))
allocate(ids%x%y ids%ids_properties%comment(1))
= 'IDS put by put_slice'
call ids_put_non_timed(idx,"core_profiles",ids)
!SCALARS (!)
do i=1, 10
ids%time(i) = VALUE
ids%x%y(i) = VALUE
enddo
! VECTORS IDS structure allocation
allocate(ids%time(1))
allocate(ids%x%y(1))
ids%time(1) = timeVectorVALUE
ids%x%y ids%x%y(1) = valueVectorVALUE
call ids_put_slice(idx, 'core_profiles', ids)
call ids_deallocate(ids)
! Close a pulse file
call imas_close(idx)
end program
|
|
Let's check how to read these data in Fortran.
3.2
...
.4 CPO/IDS get
Exercise no. 4 - After this exercise you will:
get() 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_open('euitm', 14, 4, idx)
! Get data
call euitm_get(idx, 'equilibrium', cpoArray)
! Check array size
arraySize = size(eqArraycpoArray)
! write (*,*) "Number of slices: ", arraySize<= array of CPOs
! SCALARS (!)
do i=1, arraySize
write (*,*) "Time : ", cpoArray(i)%time
write (*,*) "Value: ", cpoArray(i)%x%y
enddo
! 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, arraySize
type (ids_core_profiles) :: ids ! <= Single object !!!
! Open a database
call imas_open('ids', 14, 4, idx)
! Get data
call imasids_get(idx, 'core_profiles', ids)
! Check array size
arraySize arraySize = size(ids%time)
! <= write (*,*) "Number of slices: ", arraySizetime vector
! SCALARS (!)
do i=1, arraySize
write (*,*) "Time : ", ids%time(i)
write (*,*) "Value: ", ids%x%y(i)
enddo
! VECTORS
write (*,*) "Time : ", ids%time
write (*,*) "Value: ", ids%x%y
! Close a pulse file
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(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 |
|