Skip to content
Snippets Groups Projects
Commit 7b6ab7f8 authored by Cenk Yildiz's avatar Cenk Yildiz
Browse files

Add possibility to chose hdf5 backend for saving ids data

* Add imas_backend option to 2 functions
* Use imas_open_env_backend instead of imas_create_env
parent efc30123
No related branches found
No related tags found
1 merge request!140Add possibility to chose hdf5 backend for saving ids data
Pipeline #177988 passed
function [ids_put_status] = ids2database(shot,run,occurence,ids2put,tree_user,tree_tokamak,tree_majorversion,varargin); function [ids_put_status] = ids2database(shot,run,occurence,ids2put,tree_user,tree_tokamak,tree_majorversion,imas_backend,varargin);
% %
% [ids_put_status] = ids2database(shot,run,occurence,ids2put,varargin); % [ids_put_status] = ids2database(shot,run,occurence,ids2put,varargin);
% %
...@@ -7,6 +7,7 @@ function [ids_put_status] = ids2database(shot,run,occurence,ids2put,tree_user,tr ...@@ -7,6 +7,7 @@ function [ids_put_status] = ids2database(shot,run,occurence,ids2put,tree_user,tr
% tree_name: getenv('USER') by default, can be 'public' % tree_name: getenv('USER') by default, can be 'public'
% tree_tokamak: 'tcv' by default % tree_tokamak: 'tcv' by default
% tree_majorversion: '3' by default % tree_majorversion: '3' by default
% imas_backend: "MDSplus" or "HDF5"
% %
% varargin{1}: tbd % varargin{1}: tbd
% %
...@@ -16,6 +17,7 @@ ids_put_status = 0; ...@@ -16,6 +17,7 @@ ids_put_status = 0;
tree_user_default = getenv('USER'); tree_user_default = getenv('USER');
tree_tokamak_default = 'tcv'; tree_tokamak_default = 'tcv';
tree_majorversion_default = '3'; tree_majorversion_default = '3';
imas_backend_default = 'MDSplus';
% initialize input parser % initialize input parser
p = inputParser; p = inputParser;
...@@ -28,6 +30,7 @@ p.addOptional('ids2put', struct([]), @(x) (isstruct(x))); ...@@ -28,6 +30,7 @@ p.addOptional('ids2put', struct([]), @(x) (isstruct(x)));
p.addOptional('tree_user', tree_user_default, @(x) (isempty(x) || ischar(x))); p.addOptional('tree_user', tree_user_default, @(x) (isempty(x) || ischar(x)));
p.addOptional('tree_tokamak', tree_tokamak_default, @(x) (isempty(x) || ischar(x))); p.addOptional('tree_tokamak', tree_tokamak_default, @(x) (isempty(x) || ischar(x)));
p.addOptional('tree_majorversion', tree_majorversion_default, @(x) (ischar(x))); p.addOptional('tree_majorversion', tree_majorversion_default, @(x) (ischar(x)));
p.addOptional('imas_backend', imas_backend_default, @(x) (isempty(x) || ischar(x)));
p.parse; p.parse;
defaults_ids2database = p.Results; % to keep track of defaults defaults_ids2database = p.Results; % to keep track of defaults
...@@ -53,8 +56,11 @@ elseif nargin==6 ...@@ -53,8 +56,11 @@ elseif nargin==6
elseif nargin==7 elseif nargin==7
p.parse(shot,run,occurence,ids2put,tree_user,tree_tokamak,tree_majorversion); p.parse(shot,run,occurence,ids2put,tree_user,tree_tokamak,tree_majorversion);
params = p.Results; params = p.Results;
elseif nargin>=8 elseif nargin==8
p.parse(shot,run,occurence,ids2put,tree_user,tree_tokamak,tree_majorversion,varargin{:}); p.parse(shot,run,occurence,ids2put,tree_user,tree_tokamak,tree_majorversion,imas_backend);
params = p.Results;
elseif nargin>=9
p.parse(shot,run,occurence,ids2put,tree_user,tree_tokamak,tree_majorversion,imas_backend,varargin{:});
params = p.Results; params = p.Results;
else else
p.parse; p.parse;
...@@ -100,6 +106,19 @@ if isempty(ids_names_ok) ...@@ -100,6 +106,19 @@ if isempty(ids_names_ok)
return return
end end
if ~ismember(params_ids2database.imas_backend, {'MDSplus', 'HDF5'})
warning(['Unknown imas_backend: ', imas_backend, ', selecting default: ',imas_backend_default]);
params_ids2database.imas_backend = imas_backend_default;
end
% Get IMAS backend ID
switch params_ids2database.imas_backend
case "HDF5"
backendid=13;
case "MDSplus"
backendid=12;
end
try try
%% Initialize the three %% Initialize the three
shot_is_new = 1; % seems only create is ok even if does already exist shot_is_new = 1; % seems only create is ok even if does already exist
...@@ -109,10 +128,9 @@ try ...@@ -109,10 +128,9 @@ try
shot_is_new = 0; shot_is_new = 0;
end end
if shot_is_new if shot_is_new
idx = imas_create_env('ids',shot,run,0,0,params_ids2database.tree_user,params_ids2database.tree_tokamak, ... idx = imas_create_env_backend(shot, run, params_ids2database.tree_user,params_ids2database.tree_tokamak, params_ids2database.tree_majorversion, backendid)
params_ids2database.tree_majorversion); %
else else
idx = imas_open_env('ids',shot,run,params_ids2database.tree_user,params_ids2database.tree_tokamak,params_ids2database.tree_majorversion); % idx = imas_open_env_backend(shot,run,params_ids2database.tree_user,params_ids2database.tree_tokamak,params_ids2database.tree_majorversion,backendid); %
end end
%% Put the field %% Put the field
......
...@@ -10,6 +10,7 @@ function [ids_from_tcv,varargout] = tcv2ids2database(shot,run_out,varargin); ...@@ -10,6 +10,7 @@ function [ids_from_tcv,varargout] = tcv2ids2database(shot,run_out,varargin);
% varargin: 'occurence': occurence value % varargin: 'occurence': occurence value
% varargin: 'ids_names': cell, ids to load, by default all defined so far (if empty or empty string or not given) % varargin: 'ids_names': cell, ids to load, by default all defined so far (if empty or empty string or not given)
% see tcv_available_ids for the list of IDSs available for TCV % see tcv_available_ids for the list of IDSs available for TCV
% varargin: 'imas_backend': "MDSplus" or "HDF5"
% varargin: 'error_bar': type (string) % varargin: 'error_bar': type (string)
% 'delta' or empty (default): meaning difference in upper is set (standard error_bar % 'delta' or empty (default): meaning difference in upper is set (standard error_bar
% 'added': errorbar is added: upper=data+delta and lower=data-delta % 'added': errorbar is added: upper=data+delta and lower=data-delta
...@@ -27,6 +28,7 @@ function [ids_from_tcv,varargout] = tcv2ids2database(shot,run_out,varargin); ...@@ -27,6 +28,7 @@ function [ids_from_tcv,varargout] = tcv2ids2database(shot,run_out,varargin);
% example: % example:
% ids_from_tcv = tcv2ids2database(62745,9999,'ids_names',{'pf_active'},'error_bar','added'); % to test only one ids % ids_from_tcv = tcv2ids2database(62745,9999,'ids_names',{'pf_active'},'error_bar','added'); % to test only one ids
% ids_from_tcv = tcv2ids2database(62745,9999,'error_bar','added'); % to get all default ids's and old errorbar type % ids_from_tcv = tcv2ids2database(62745,9999,'error_bar','added'); % to get all default ids's and old errorbar type
% ids_from_tcv = tcv2ids2database(62745,9999,'ids_names',{'summary'},'imas_backend','HDF5'); % Save data in imas HDF5 backend instead of MDSplus
% %
ids_from_tcv = []; ids_from_tcv = [];
...@@ -50,6 +52,7 @@ p.addOptional('run_out', [], @(x) (isnumeric(x) && isscalar(x) && (x == round(x) ...@@ -50,6 +52,7 @@ p.addOptional('run_out', [], @(x) (isnumeric(x) && isscalar(x) && (x == round(x)
p.addOptional('occurence', 0, @(x) isempty(x) || (isnumeric(x) && isscalar(x) && (x == round(x)))); % integer p.addOptional('occurence', 0, @(x) isempty(x) || (isnumeric(x) && isscalar(x) && (x == round(x)))); % integer
ids_names = tcv_available_ids; ids_names = tcv_available_ids;
p.addOptional('ids_names', ids_names, @(x) isempty(x) || iscell(x)); % char or cell array p.addOptional('ids_names', ids_names, @(x) isempty(x) || iscell(x)); % char or cell array
p.addOptional('imas_backend', 'MDSplus', @(x) isempty(x) || ischar(x));
p.addOptional('error_bar', 'delta', @(x) isempty(x) || ischar(x) ); % char or cell array p.addOptional('error_bar', 'delta', @(x) isempty(x) || ischar(x) ); % char or cell array
p.addOptional('tree_user', getenv('USER'), @(x) isempty(x) || ischar(x) ); % char p.addOptional('tree_user', getenv('USER'), @(x) isempty(x) || ischar(x) ); % char
p.addOptional('tree_tokamak', 'tcv', @(x) isempty(x) || ischar(x) ); % char p.addOptional('tree_tokamak', 'tcv', @(x) isempty(x) || ischar(x) ); % char
...@@ -101,8 +104,9 @@ for i=1:length(params.ids_names) ...@@ -101,8 +104,9 @@ for i=1:length(params.ids_names)
end end
params.ids_names = ids_names_ok; params.ids_names = ids_names_ok;
params_tcv2ids2database = params; params_tcv2ids2database = params;
params_not_in_tcv2ids = {'run_out','occurence','tree_user','tree_tokamak','tree_majorversion'}; params_not_in_tcv2ids = {'run_out','occurence','tree_user','tree_tokamak','tree_majorversion','imas_backend'};
params_tcv2ids = rmfield(params_tcv2ids2database,params_not_in_tcv2ids); params_tcv2ids = rmfield(params_tcv2ids2database,params_not_in_tcv2ids);
[ids_from_tcv,idsok] = tcv2ids(shot,params_tcv2ids); [ids_from_tcv,idsok] = tcv2ids(shot,params_tcv2ids);
ids_from_tcv.params_tcv2ids2database = params_tcv2ids2database; ids_from_tcv.params_tcv2ids2database = params_tcv2ids2database;
...@@ -128,7 +132,8 @@ end ...@@ -128,7 +132,8 @@ end
%% %%
[ids_put_status] = ids2database(shot,run_out,ids_from_tcv.params_tcv2ids2database.occurence,ids_from_tcv, ... [ids_put_status] = ids2database(shot,run_out,ids_from_tcv.params_tcv2ids2database.occurence,ids_from_tcv, ...
params_tcv2ids2database.tree_user,params_tcv2ids2database.tree_tokamak,params_tcv2ids2database.tree_majorversion); params_tcv2ids2database.tree_user,params_tcv2ids2database.tree_tokamak,params_tcv2ids2database.tree_majorversion, ...
params_tcv2ids2database.imas_backend);
ids_from_tcv.ids_put_status = ids_put_status; ids_from_tcv.ids_put_status = ids_put_status;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment