Skip to content
Snippets Groups Projects
tcv2ids.m 2.99 KiB
Newer Older
Olivier Sauter's avatar
Olivier Sauter committed
function [ids_saved,varargout] = tcv2ids(shot,run,varargin);
%
%   [ids_saved,varargout] = TCV2ids(shot,run,varargin);
%
% Assumes you have done: 
% >> addpath ~g2osaute/public/matlab9_11_2016 (on the gateway)
% >> mdsconnect('localhost:5555') % using the tunnel made in another session like: ssh -L 5555:tcvdata:8000 username@lac911.epfl.ch
% in another window do the tunnel: ssh -L 5555:tcvdata:8000 username@lac911.epfl.ch
% addpath ~g2osaute/public/matlab9_11_2016
% mdsconnect('localhost:5555')
%
% varargin{1}: ids to load, by default all defined so far
%             {'equilibrium', 'magnetics', 'pf_active','wall'} or a subset
%

% 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('ids_names', {'equilibrium', 'magnetics', 'pf_active','wall'}, @(x) (ischar(x) || iscell(x))); % char or cell array

p.parse;
defaults_tcv2ids = 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
  p.parse('shot',shot,'run',run,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
% check ids_names
if ~isfield(params,'ids_names')
  disp(['do not provide any ids_names or choose from : '])
  ids_saved.ids_names_available = defaults_tcv2ids.ids_names;
  defaults_tcv2ids.ids_names
  return
end
if ischar(params.ids_names)
  params.ids_names = {params.ids_names};
end
ids_names_ok = params.ids_names;
for i=1:length(params.ids_names)
  ij = strcmp(params.ids_names{i},defaults_tcv2ids.ids_names);
  if ~any(ij)
    disp(['ids name: ' params.ids_names{i} ' is not available yet, ask O. Sauter'])
    ids_names_ok = setdiff(ids_names_ok,params.ids_names{i});
  end
end
params.ids_names = ids_names_ok;
if isempty(params_tcv2ids.ids_names)
  disp('no ids names available')
  return
end
for i=1:length(params_tcv2ids.ids_names)
  ids_to_get = params_tcv2ids.ids_names{i};
  ids_empty=ids_gen(ids_to_get);
  tmp = gdat(shot,'ids','source',ids_to_get);
  ids_saved.(ids_to_get) = tmp.(ids_to_get);
  ids_saved.([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

%% 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