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')

%% Equilibrium
equil_empty=ids_gen('equilibrium');
[ids_equilibrium,ids_equilibrium_description]=tcv_get_ids_equilibrium(shot,equil_empty);
ids_saved.equilibrium = ids_equilibrium;
ids_saved.equilibrium_description = ids_equilibrium_description;

%% magnetics
magnetics_empty=ids_gen('magnetics');
[ids_magnetics,ids_magnetics_description]=tcv_get_ids_magnetics(shot,magnetics_empty);
ids_saved.magnetics = ids_magnetics;
ids_saved.magnetics_description = ids_magnetics_description;

%% pf_active
pf_active_empty=ids_gen('pf_active');
[ids_pf_active,ids_pf_active_description]=tcv_get_ids_pf_active(shot,pf_active_empty);
ids_saved.pf_active = ids_pf_active;
ids_saved.pf_active_description = ids_pf_active_description;

%% wall
pf_wall_empty=ids_gen('wall');
[ids_wall,ids_wall_description]=tcv_get_ids_wall(shot,pf_wall_empty);
ids_saved.pf_wall = ids_wall;
ids_saved.pf_wall_descrption = ids_wall_description;


%% 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
ids_put(idx,'equilibrium',ids_equilibrium);
ids_put(idx, 'magnetics', ids_magnetics);
ids_put(idx, 'pf_active', ids_pf_active);
ids_put(idx, 'wall', ids_wall);

%% Close the file
imas_close(idx)


