Skip to content
Snippets Groups Projects
Commit 7107d9ad authored by Olivier Sauter's avatar Olivier Sauter
Browse files

separate getting ids from TCV and writing ids to database, fix name as string...

separate getting ids from TCV and writing ids to database, fix name as string not cell in pf_active_circuit

git-svn-id: https://spcsvn.epfl.ch/repos/TCV/gdat/trunk@11411 d63d8f72-b253-0410-a779-e742ad2e26cf
parent e75e7f2f
No related branches found
No related tags found
No related merge requests found
function [ids_put_status] = ids2database(shot,run,occurence,ids2put,varargin);
%
% [ids_put_status] = ids2database(shot,run,occurence,ids2put,varargin);
%
% open/create shot,run and put the ids from ids2put.idsnames (names from fieldnames(ids2put) && within IDS_list)
%
% varargin{1}: tbd
%
%
ids_put_status = 0;
% initialize input parser
p = inputParser;
% no required inputs here so one can call with empty args and get defaults parameters
% effectively required inputs should have defaults as empty
p.addOptional('shot', [], @(x) (isnumeric(x) && isscalar(x) && (x == round(x)))); % integer
p.addOptional('run', [], @(x) (isnumeric(x) && isscalar(x) && (x == round(x)))); % integer
p.addOptional('occurence', 0, @(x) isempty(x) || (isnumeric(x) && isscalar(x) && (x == round(x)))); % integer
p.addOptional('ids2put', struct([]), @(x) (isstruct(x)));
p.parse;
defaults_ids2database = p.Results; % to keep track of defaults
if nargin==1
p.parse(shot);
params = p.Results;
elseif nargin==2
p.parse(shot,run);
params = p.Results;
elseif nargin==3 && ~ischar(occurence)
p.parse(shot,run,occurence);
params = p.Results;
elseif nargin>=4
p.parse(shot,run,occurence,varargin{:});
params = p.Results;
else
p.parse;
p.Results
return
end
% replace empty inputs with defaults
names = fieldnames(params);
mask = structfun(@isempty,params);
if any(mask),
params = rmfield(params,unique([names(mask); p.UsingDefaults.']));
end
params_ids2database = params;
% check ids_names
ids_names=fieldnames(ids2put);
ids_full_list = IDS_list;
ids_names_notok = setdiff(ids_names,ids_full_list);
if ~isempty(ids_names_notok)
disp(['these subfields are not ids names, so not used: ' sprintf('%s ',ids_names_notok{:})])
end
ids_names_ok = intersect(ids_full_list,ids_names);
if isempty(ids_names_ok)
disp('no ids names available compatible with IDS_list')
return
end
try
%% Initialize the three
shot_is_new = 1; % seems only create is ok even if does already exist
mdsplustree0=getenv('MDSPLUS_TREE_BASE_0');
[aa,bb]=unix(['ls ' mdsplustree0 '/*' num2str(shot) num2str(run,'%4.4d') '*.tree']);
if aa==0
shot_is_new = 0;
end
if shot_is_new
idx = imas_create('ids',shot,run,0,0); %
else
idx = imas_open('ids',shot,run); %
end
%% Put the field
for i=1:length(ids_names_ok)
ids_to_get = ids_names_ok{i};
if occurence <= 0
ids_put(idx,ids_to_get,ids2put.(ids_to_get));
else
ids_put(idx,[ids_to_get '/' num2str(occurence)],ids2put.(ids_to_get));
end
end
%% Close the file
imas_close(idx)
catch ME
disp('problems in putting data in database:')
throw(ME)
idx
keyboard
end
function [ids_saved,varargout] = tcv2ids(shot,run,varargin); function [ids_from_tcv,varargout] = tcv2ids(shot,varargin);
% %
% [ids_saved,varargout] = tcv2ids(shot,run,varargin); % [ids_from_tcv,varargout] = tcv2ids(shot,varargin);
% %
% Assumes you have done: % Assumes you have done:
% >> addpath ~g2osaute/public/matlab9_11_2016 (on the gateway) % >> addpath ~g2osaute/public/matlab9_11_2016 (on the gateway)
...@@ -10,7 +10,7 @@ function [ids_saved,varargout] = tcv2ids(shot,run,varargin); ...@@ -10,7 +10,7 @@ function [ids_saved,varargout] = tcv2ids(shot,run,varargin);
% addpath ~g2osaute/public/matlab9_11_2016 % addpath ~g2osaute/public/matlab9_11_2016
% mdsconnect('localhost:5555') % mdsconnect('localhost:5555')
% %
% varargin{1}: ids to load, by default all defined so far % varargin{1}: ids to load, by default all defined so far (if empty or empty string or not given)
% {'equilibrium', 'magnetics', 'pf_active','wall'} or a subset % {'equilibrium', 'magnetics', 'pf_active','wall'} or a subset
% %
% varargout{1}: return also the ids in array of structure with the names, to allow easy use of plotallids % varargout{1}: return also the ids in array of structure with the names, to allow easy use of plotallids
...@@ -21,8 +21,7 @@ p = inputParser; ...@@ -21,8 +21,7 @@ p = inputParser;
% no required inputs here so one can call with empty args and get defaults parameters % no required inputs here so one can call with empty args and get defaults parameters
% effectively required inputs should have defaults as empty % effectively required inputs should have defaults as empty
p.addOptional('shot', [], @(x) (isnumeric(x) && isscalar(x) && (x == round(x)))); % integer p.addOptional('shot', [], @(x) (isnumeric(x) && isscalar(x) && (x == round(x)))); % integer
p.addOptional('run', [], @(x) (isnumeric(x) && isscalar(x) && (x == round(x)))); % integer p.addOptional('ids_names', {'equilibrium', 'magnetics', 'pf_active','wall', 'tf'}, @(x) isempty(x) | (ischar(x) || iscell(x))); % char or cell array
p.addOptional('ids_names', {'equilibrium', 'magnetics', 'pf_active','wall', 'tf'}, @(x) (ischar(x) || iscell(x))); % char or cell array
p.parse; p.parse;
defaults_tcv2ids = p.Results; % to keep track of defaults defaults_tcv2ids = p.Results; % to keep track of defaults
...@@ -30,11 +29,8 @@ defaults_tcv2ids = p.Results; % to keep track of defaults ...@@ -30,11 +29,8 @@ defaults_tcv2ids = p.Results; % to keep track of defaults
if nargin==1 if nargin==1
p.parse(shot); p.parse(shot);
params = p.Results; params = p.Results;
elseif nargin==2 elseif nargin>=2
p.parse(shot,run); p.parse(shot,varargin{:});
params = p.Results;
elseif nargin>=3
p.parse('shot',shot,'run',run,varargin{:});
params = p.Results; params = p.Results;
else else
p.parse; p.parse;
...@@ -47,12 +43,18 @@ names = fieldnames(params); ...@@ -47,12 +43,18 @@ names = fieldnames(params);
mask = structfun(@isempty,params); mask = structfun(@isempty,params);
if any(mask), if any(mask),
params = rmfield(params,unique([names(mask); p.UsingDefaults.'])); params = rmfield(params,unique([names(mask); p.UsingDefaults.']));
if ~isfield(params, 'shot') || isnan(params.shot)
warning('No shot entered');
return
end
p.parse(params.shot,rmfield(params,'shot'));
params = p.Results;
end end
% check ids_names % check ids_names
if ~isfield(params,'ids_names') if ~isfield(params,'ids_names')
disp(['do not provide any ids_names or choose from : ']) disp(['do not provide any ids_names or choose from : '])
ids_saved.ids_names_available = defaults_tcv2ids.ids_names; ids_from_tcv.ids_names_available = defaults_tcv2ids.ids_names;
defaults_tcv2ids.ids_names defaults_tcv2ids.ids_names
return return
end end
...@@ -80,32 +82,20 @@ for i=1:length(params_tcv2ids.ids_names) ...@@ -80,32 +82,20 @@ for i=1:length(params_tcv2ids.ids_names)
ids_to_get = params_tcv2ids.ids_names{i}; ids_to_get = params_tcv2ids.ids_names{i};
ids_empty=ids_gen(ids_to_get); ids_empty=ids_gen(ids_to_get);
tmp = gdat(shot,'ids','source',ids_to_get,'machine','tcv'); tmp = gdat(shot,'ids','source',ids_to_get,'machine','tcv');
ids_saved.(ids_to_get) = tmp.(ids_to_get); ids_from_tcv.(ids_to_get) = tmp.(ids_to_get);
ids_saved.([ids_to_get '_description']) = tmp.([ids_to_get '_description']); ids_from_tcv.([ids_to_get '_description']) = tmp.([ids_to_get '_description']);
end
%% Initialize the three
shot_is_new = 1; % seems only create is ok even if does already exist
if shot_is_new
idx = imas_create('ids',shot,run,run,run); %
else
idx = imas_open('ids',shot,run); %
end end
%% Put the field
for i=1:length(params_tcv2ids.ids_names)
ids_to_get = params_tcv2ids.ids_names{i};
ids_put(idx,ids_to_get,ids_saved.(ids_to_get));
end
%% Close the file
imas_close(idx)
if nargout>=2 if nargout>=2
for i=1:length(params_tcv2ids.ids_names) try
ids_to_get = params_tcv2ids.ids_names{i}; for i=1:length(params_tcv2ids.ids_names)
varargout{1}.ids{i} = ids_saved.(ids_to_get); ids_to_get = params_tcv2ids.ids_names{i};
varargout{1}.idsname{i} = ids_to_get; varargout{1}.ids{i} = ids_from_tcv.(ids_to_get);
varargout{1}.ids{i}.idsname = ids_to_get; varargout{1}.idsname{i} = ids_to_get;
varargout{1}.ids{i}.idsname = ids_to_get;
end
catch
varargout{1} = [];
disp('problems to fill in varargout')
end end
end end
%
% script to get TCV data as ids and then write them on the database
%
shot=40000;
run_out=999;
occurence=0;
ids2get = []; % default will load all defined so far
[ids_from_tcv,idsok] = tcv2ids(shot,ids2get);
% can plot with: [plotids_H] = plotids([],idsok.ids{1},idsok.ids{2});
[ids_put_status] = ids2database(shot,run_out,occurence,ids_from_tcv);
...@@ -11,10 +11,6 @@ for ii=1:tcv_circuit_info.ntotcircuits ...@@ -11,10 +11,6 @@ for ii=1:tcv_circuit_info.ntotcircuits
ids_struct_out{ii}.current.data = tmpdata.data; ids_struct_out{ii}.current.data = tmpdata.data;
ids_struct_out{ii}.current.time = tmpdata.dim{1}; ids_struct_out{ii}.current.time = tmpdata.dim{1};
ids_struct_out{ii}.connections = tcv_circuit_info.connection_matrix{ii}; ids_struct_out{ii}.connections = tcv_circuit_info.connection_matrix{ii};
ids_struct_out{ii}.name = tcv_circuit_info.circuit_names{ii}; ids_struct_out{ii}.name = tcv_circuit_info.circuit_names{ii}{1};
end end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment