Create DBEntry from scratch using legacy modeΒΆ
This example focuses on creating DBEntry using legacy mode method.
See also
- API documentation for:
Warning
The legacy method is deprecated from AL>=5.0.0.
It is recommended to use the URI approach instead.
!!! URI based approach.
subroutine open_db_entry_uri
use ids_routines
implicit none
integer :: pulse = 1 ! pulse number of MDS+ file
integer :: run = 10 ! shot number of MDS+ file
character(len=5) :: version = '3' ! DD major version schema
integer :: idx ! index of opened input file
integer :: status ! error code of the operation
character(:), allocatable :: errmsg ! optional returned error message
integer :: i ! used for loops over timed values
integer :: backendId ! identification number of backend used in this example
character(len=256) :: userName ! name of the user running the code
character(len=10) :: dbName = 'test' ! name of the database
character(len=5) :: treeName = 'ids' ! name of the MDS+ tree structure
character(strmaxlen) :: uri ! uri containes location of the data
character(len=1024) :: options = '' ! options to be passed to backend
! Available backends are:
! ascii | 11 - only for debugging purposes
! mdsplus | 12
! hdf5 | 13
! memory | 14 - data is lost after entry is closed
! uda | 15
backendId = 12
! Get users name so we can access their personal database.
call get_environment_variable( "USER" , userName)
! We follow here the code presented in Python where URI is a formatted string with various parameters.
! In Fortran we have to use al_build_uri_from_legacy_parameters() subroutine
call al_build_uri_from_legacy_parameters(backendId, pulse, run, userName, dbName, version, options, uri, status)
write(*,*) 'Prepared uri: ', trim(uri)
! Create the database entry by providing an IMAS URI
! Make sure to trim uri - we want to avoid any leading and trailing spaces.
call imas_open(trim(uri), FORCE_CREATE_PULSE, idx, status, errmsg)
if (status.ne.0) then
write(*,*) 'Error! Issue while creating MDS+ file: '//errmsg
end if
! Remember to close entry when you are done with it
call imas_close(idx, status)
end subroutine open_db_entry_uri