Skip to content
Snippets Groups Projects
loadKSTARdata.m 23.4 KiB
Newer Older
Olivier Sauter's avatar
Olivier Sauter committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639
function [trace,error,varargout]=loadKSTARdata(shot,data_type,varargin)
%
% data_type:
% 'Ip'   =  current
% 'zmag' =  vertical position of the center of the plasma (magnetic axis)
% 'rmag' =  radial position of the center of the plasma 
% 'rcont' =  R of plama boundary vs time
% 'zcont' =  Z of plama boundary vs time
% 'vol' =  volume of flux surfaces vs rho=sqrt(psi)
% 'qrho' =  q profile on rho mesh
% 'q95' =  q95 vs time
% 'kappa', 'elon' =  edge elongation vs time
% 'delta', 'triang' =  edge averaged triangularity vs time
% 'deltatop', 'triangtop' =  edge upper (top) triangularity vs time
% 'deltabot', 'triangbot' =  edge lower (bottom) triangularity vs time
% 'n1' or 'n2': n=1 or n=2 MHD signal
% 'neint' =  line-integrated electron density [m/m^3]
% 'ne'= ne raw profile on (R,t). ADD error bars in .std
% 'te'= Te raw profile on (R,t). ADD error bars in .std
% 'nerho'= ne profile on (rho=sqrt(psi),time) mesh.Note rho is a 2D array as depends on time. ADD error bars in .std
% 'terho'= Te profile on (rho=sqrt(psi),time) mesh.Note rho is a 2D array as depends on time. ADD error bars in .std
%          Now, use CHAIN2 lid2/neo and teo for nerho, terho
% 'ece'  =  electron cyclotron emission
% 'sxr'  =  soft x-ray emission 
% 'sxR'  =  soft x-ray emission with varargout{1} option (requires varargin{5}!)
% 'halpha'= Dalpha signal
%
%
% INPUT:
% shot: shot number
% data_type: type of the required data.
%
% Allows extension for uid and seq number a la RDA: ?uid=jetthg+seq=110
% examples:
%
%                          data_type='Ip?uid=jetthg+seq=110'
%                          data_type='ppf','efit/xip?uid=jetthg+seq=110'
%
% for EFIT traces, allows keyword extension '_m' to get data from ppf/efitm instead of ppf/efit
% examples:
%
%                          data_type='Ip_m?uid=jetthg+seq=110'
%                          data_type='ppf','efitm/xip?uid=jetthg+seq=110'
%
% Meaning of varargin depends on data_type:
%
% data_type=sxr or ece:
%                  varargin{1}:  [i1 i2] : if not empty, assumes need many chords from i1 to i2
%                  varargin{2}:  channel status: 1=unread yet, 0=read
%                                (for traces with many channel, enables to load additional channels,
%                                 like SXR, ECE, etc.)
%                  varargin{3}:  zmag for varargout{1} computation
%                  varargin{4}, {5} (used by AUG, time interval and skip interval to reduce time points)
%                  varargin{6}: sxr camera extra option: use to choose R projection: 
%                               empty or '0'=default (intersection with zmag with 5 degrees)
%                               '1'=fixed to B. Alper R array (fixed in time)
%
% OUTPUT:
% trace.data:   data structure
% trace.t:      time of reference 
% trace.x:      space of reference 
% error:        error in loading signal (0=> OK, 1=> error)
%
% Additional Output arguments depending on data_type
%
% data_type=sxR:
%                varargout{1}: intersection of the view lines with magnetic axis
%                              uses 5 degrees and zmag (varargin{3} if given) as default
%                              if varargin{4}==1, uses B. Alper fixed R array for V camera
%
% functions needed: jetreaddata or mdsplus routines
%
% Example:
%         [zmag,error]=loadKSTARdata(shot,'zmag');
%         [n2,error]=loadKSTARdata(shot,'jpf/da/c1-g102');
%         [halpha,error]=loadKSTARdata(shot,'jpf/dd/s3-ad35');
%

varargout={cell(1,1)};
error=1;

% To allow multiple ways of writing a specific keyword, use data_type_eff within this routine
data_type_eff=data_type;
if size(data_type_eff,1)==1
  i=findstr('/',data_type_eff);
  if length(i)>1
    % assumes given a la 'ppf/efit/xip'
    data_type_eff=[{data_type_eff(1:i(1)-1)} ; {data_type_eff(i(1)+1:end)}];
  end
end

i_efitm=0;
i_ext=length(data_type_eff)+1;
name_ext='';
if size(data_type_eff,1)==1
  i=findstr('?',data_type_eff);
  if ~isempty(i)
    i_ext=i;
    name_ext=data_type_eff(i_ext:end);
  end
  data_type_eff_noext=data_type_eff(1:i_ext-1);
  i=findstr('_m',data_type_eff_noext);
  if ~isempty(i)
    i_efitm=1;
    data_type_eff_noext=data_type_eff(1:i-1);
  end
  if ~isempty(strmatch(data_type_eff_noext,[{'ip'} {'i_p'} {'xip'}],'exact'))
    data_type_eff_noext='Ip';
  end
  if ~isempty(strmatch(data_type_eff_noext,[{'Te'} {'t_e'} {'TE'} {'T_e'}],'exact'))
    data_type_eff_noext='te';
  end
  if ~isempty(strmatch(data_type_eff_noext,[{'Ne'} {'n_e'} {'NE'} {'N_e'}],'exact'))
    data_type_eff_noext='ne';
  end
  if ~isempty(strmatch(data_type_eff_noext,[{'Terho'}],'exact'))
    data_type_eff_noext='terho';
  end
  if ~isempty(strmatch(data_type_eff_noext,[{'SXR'}],'exact'))
    data_type_eff_noext='sxr';
  end
  if ~isempty(strmatch(data_type_eff_noext,[{'ECE'}],'exact'))
    data_type_eff_noext='ece';
  end
  if ~isempty(strmatch(data_type_eff_noext,[{'VOL'} {'volume'}],'exact'))
    data_type_eff_noext='vol';
  end
  if ~isempty(strmatch(data_type_eff_noext,[{'q_95'} {'Q95'}],'exact'))
    data_type_eff_noext='q95';
  end
  if ~isempty(strmatch(data_type_eff_noext,[{'elongation'} {'elon'}],'exact'))
    data_type_eff_noext='kappa';
  end
  if ~isempty(strmatch(data_type_eff_noext,[{'triangularity'} {'triang'}],'exact'))
    data_type_eff_noext='delta';
  end
  if ~isempty(strmatch(data_type_eff_noext,[{'deltaup'} {'deltau'} {'triangtop'} {'triangu'} {'triangup'}],'exact'))
    data_type_eff_noext='deltatop';
  end
  if ~isempty(strmatch(data_type_eff_noext,[{'deltalow'} {'deltal'} {'triangbot'} {'triangl'} {'trianglow'}],'exact'))
    data_type_eff_noext='deltabot';
  end
  if ~isempty(strmatch(data_type_eff_noext,[{'halpha'} {'Halpha'}],'exact'))
    data_type_eff_noext='halpha';
  end
  if ~isempty(strmatch(data_type_eff_noext,[{'n1'} {'N1'}],'exact'))
    data_type_eff_noext='n1';
  end
  if ~isempty(strmatch(data_type_eff_noext,[{'n2'} {'N2'}],'exact'))
    data_type_eff_noext='n2';
  end
  if ~isempty(strmatch(data_type_eff_noext,[{'Rmag'}],'exact'))
    data_type_eff_noext='rmag';
  end
  if ~isempty(strmatch(data_type_eff_noext,[{'Zmag'}],'exact'))
    data_type_eff_noext='zmag';
  end
  if ~isempty(strmatch(data_type_eff_noext,[{'Rcont'}],'exact'))
    data_type_eff_noext='rcont';
  end
  if ~isempty(strmatch(data_type_eff_noext,[{'Zcont'}],'exact'))
    data_type_eff_noext='zcont';
  end
else
  i_ext=length(data_type_eff{2})+1;
  name_ext='';
  i=findstr('?',data_type_eff{2});
  if ~isempty(i)
    i_ext=i;
    name_ext=data_type_eff{2}(i_ext:end);
  end
  data_type_eff_noext=data_type_eff{2}(1:i_ext-1);
end

% all keywords and corresponding case to run below
KSTARkeywrdall=[{'Ip'} {'zmag'} {'rmag'} {'rcont'} {'zcont'} {'vol'} {'qrho'} {'q95'} {'kappa'} ...
      {'delta'} {'deltatop'} {'deltabot'} {'halpha'} {'n1'} {'n2'} {'neint'} ...
      {'ne'} {'te'} {'nerho'} {'terho'} ...
      {'sxr'} {'sxR'} {'ece'}];
KSTARsig.iip=strmatch('Ip',KSTARkeywrdall,'exact');
KSTARsig.izmag=strmatch('zmag',KSTARkeywrdall,'exact');
KSTARsig.irmag=strmatch('rmag',KSTARkeywrdall,'exact');
KSTARsig.ircont=strmatch('rcont',KSTARkeywrdall,'exact');
KSTARsig.izcont=strmatch('zcont',KSTARkeywrdall,'exact');
KSTARsig.ivol=strmatch('vol',KSTARkeywrdall,'exact');
KSTARsig.iqrho=strmatch('qrho',KSTARkeywrdall,'exact');
KSTARsig.iq95=strmatch('q95',KSTARkeywrdall,'exact');
KSTARsig.ikappa=strmatch('kappa',KSTARkeywrdall,'exact');
KSTARsig.idelta=strmatch('delta',KSTARkeywrdall,'exact');
KSTARsig.ideltatop=strmatch('deltatop',KSTARkeywrdall,'exact');
KSTARsig.ideltabot=strmatch('deltabot',KSTARkeywrdall,'exact');
KSTARsig.ihalpha=strmatch('halpha',KSTARkeywrdall,'exact');
KSTARsig.in1=strmatch('n1',KSTARkeywrdall,'exact');
KSTARsig.in2=strmatch('n2',KSTARkeywrdall,'exact');
KSTARsig.ineint=strmatch('neint',KSTARkeywrdall,'exact');
KSTARsig.ine=strmatch('ne',KSTARkeywrdall,'exact');
KSTARsig.ite=strmatch('te',KSTARkeywrdall,'exact');
KSTARsig.inerho=strmatch('nerho',KSTARkeywrdall,'exact');
KSTARsig.iterho=strmatch('terho',KSTARkeywrdall,'exact');
KSTARsig.isxr=strmatch('sxr',KSTARkeywrdall,'exact');
KSTARsig.isxR=strmatch('sxR',KSTARkeywrdall,'exact');
KSTARsig.iece=strmatch('ece',KSTARkeywrdall,'exact');

% For each keyword, specify which case to use. As most common is 'simplereaddata', fill in with this and change
% only indices needed. Usually use name of case same as keyword name
KSTARkeywrdcase=cell(size(KSTARkeywrdall));
KSTARkeywrdcase(:)={'simplereaddata'};
KSTARkeywrdcase(KSTARsig.iqrho)=KSTARkeywrdall(KSTARsig.iqrho); % special as efit q on psi
KSTARkeywrdcase(KSTARsig.idelta)=KSTARkeywrdall(KSTARsig.idelta); % special as average of triu and tril
KSTARkeywrdcase(KSTARsig.ine)=KSTARkeywrdall(KSTARsig.ine); % special as adds error bars
KSTARkeywrdcase(KSTARsig.ite)=KSTARkeywrdall(KSTARsig.ite); % idem
KSTARkeywrdcase(KSTARsig.inerho)=KSTARkeywrdall(KSTARsig.inerho); % idem
KSTARkeywrdcase(KSTARsig.iterho)=KSTARkeywrdall(KSTARsig.iterho); % idem
KSTARkeywrdcase(KSTARsig.isxr)=KSTARkeywrdall(KSTARsig.isxr);
KSTARkeywrdcase(KSTARsig.isxR)=KSTARkeywrdall(KSTARsig.isxR);
KSTARkeywrdcase(KSTARsig.iece)=KSTARkeywrdall(KSTARsig.iece);

% Information about which dimension has time, always return 2D data as (x,t) array
% as most are 1D arrays with time as first index, fill in with ones and change only those needed
KSTARsigtimeindx=ones(size(KSTARkeywrdall));

% For the 'simplereaddata' cases, we need the full node in case gdat was called with full location directly
% for the other cases, leave this location empty
KSTARsiglocation=cell(2,size(KSTARkeywrdall,2));
KSTARsiglocation(:)={''};
KSTARsiglocation(:,KSTARsig.iip)={'ppf'; 'efit/xip'};
KSTARsiglocation(:,KSTARsig.izmag)={'ppf'; 'efit/zmag'};
KSTARsiglocation(:,KSTARsig.irmag)={'ppf'; 'efit/rmag'};
KSTARsiglocation(:,KSTARsig.ircont)={'ppf' ; 'efit/rbnd'}; KSTARsigtimeindx(KSTARsig.ircont)=2;
KSTARsiglocation(:,KSTARsig.izcont)={'ppf' ; 'efit/zbnd'}; KSTARsigtimeindx(KSTARsig.izcont)=2;
KSTARsiglocation(:,KSTARsig.ivol)={'ppf'; 'equi/vol'};
KSTARsiglocation(:,KSTARsig.iq95)={'ppf'; 'efit/q95'};
KSTARsiglocation(:,KSTARsig.ikappa)={'ppf'; 'efit/elon'};
KSTARsiglocation(:,KSTARsig.ideltatop)={'ppf'; 'efit/triu'};
KSTARsiglocation(:,KSTARsig.ideltabot)={'ppf'; 'efit/tril'};
KSTARsiglocation(:,KSTARsig.ihalpha)={'jpf'; 'dd/s3-ad35'};
KSTARsiglocation(:,KSTARsig.in1)={'jpf'; 'da/c1-g101'};
KSTARsiglocation(:,KSTARsig.in2)={'jpf'; 'da/c1-g102'};
KSTARsiglocation(:,KSTARsig.ineint)={'ppf'; 'kg1v/lid3'};

% initialize order of substructures and allows just a "return" if data empty
trace.data=[];
trace.x=[];
trace.t=[];
trace.dim=[];
trace.dimunits=[];
trace.name=[];

% find index of signal called upon
if size(data_type_eff,1)==2
  % in case node name was given in 2 parts directly (as old way)
  ii1=strmatch(data_type_eff(1),KSTARsiglocation(1,:),'exact');
  iiindex=strmatch(data_type_eff_noext,KSTARsiglocation(2,ii1),'exact');
  if ~isempty(iiindex)
    index=ii1(iiindex);
  else
    index=[];
  end
  if isempty(index)
% $$$     disp('********************')
% $$$     disp('trace not yet registered.')
% $$$     disp('If standard data, ask andrea.scarabosio@epfl.ch or olivier.sauter@epfl.ch to create a keyqord entry for this data')
%    eval(['!mail -s ''' data_type_eff{1} ' ' data_type_eff{2} ' ' num2str(shot) ' ' ...
%          getenv('USER') ' KSTAR'' olivier.sauter@epfl.ch < /dev/null'])
    disp('********************')
    % temporarily add entry in arrays, so can work below
    index=length(KSTARkeywrdall)+1;
    KSTARkeywrdall(end+1)={'new'};
    KSTARkeywrdcase(end+1)={'simplereaddata'};
    KSTARsiglocation(1:2,end+1)=[data_type_eff(1) ; {data_type_eff_noext}];
    KSTARsigtimeindx(end+1)=0;
  elseif ~strcmp(KSTARkeywrdcase{index},'simplereaddata')
    msgbox(['Problem in loadKSTARdata with data_type_eff = ' char(data_type_eff(end)) ...
          '. Full paths of nodes should only be for case simplereaddata'],'in loadKSTARdata','error')
    error('in loadKSTARdata')
  end
else
  index=strmatch(data_type_eff_noext,KSTARkeywrdall,'exact');
  if isempty(index)
    disp(' ')
    disp('********************')
    if iscell(data_type_eff)
      disp(['no such keyword: ' data_type_eff{1} '/' data_type_eff{2}])
    else
      disp(['no such keyword: ' data_type_eff])
    end
    disp(' ')
    disp('Available keywords:')
    KSTARkeywrdall(:)
    disp('********************')
    return
  end
end
disp(' ')
if iscell(data_type_eff)
  disp(['loading' ' ' data_type_eff{1} '/' data_type_eff{2} ' from KSTAR shot #' num2str(shot)]); 
else
  disp(['loading' ' ' data_type_eff ' from KSTAR shot #' num2str(shot)]); 
end
disp(['case ' KSTARkeywrdcase{index}])
disp(' ')
switch KSTARkeywrdcase{index}

  %&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  case 'simplereaddata'

    ppftype=KSTARsiglocation{1,index};
    if i_efitm; 
      tracename=['eftm' KSTARsiglocation{2,index}(5:end) name_ext];
    else
      tracename=[KSTARsiglocation{2,index} name_ext];
    end
    ij=find(tracename~='''');
    tracename=tracename(ij);
    [a,x,t,d,e]=rda_eff(shot,ppftype,tracename);
    switch tracename
      case {'efit/btpd','efit/btpd?uid=jetppf+seq=0'}
        if isempty(a) | isempty(t);
          disp('data or t empty, assumes means btpd not defined');
          [xip,x,t,d,e]=rda_eff(shot,'ppf','efit/xip');
          shot_mg3_list=[47274 47275 47276 47280 47281 47282 47283 47284 47285 47286 47287 47290 47295 47296 47301];
          if isempty(find(shot_mg3_list==shot))
            [wdia,x1,t1,d,e]=rda_eff(shot,'ppf','efit/wdia');
          else
            [wdia,x1,t1,d,e]=rda_eff(shot,'ppf','mg3/wpd');
            wdia=interp1(t1,wdia,t);
          end
          [rgeo,x3,t3,d,e]=rda_eff(shot,'ppf','efit/rgeo');
          a=2.122e6 .* wdia ./xip.^2 ./ rgeo;
        end
      case {'efit/btnd','efit/btnd?uid=jetppf+seq=0'}
        if isempty(a) | isempty(t);
          disp('data or t empty, assumes means btnd not defined');
          [xip,x,t,d,e]=rda_eff(shot,'ppf','efit/xip');
          shot_mg3_list=[47274 47275 47276 47280 47281 47282 47283 47284 47285 47286 47287 47290 47295 47296 47301];
          if isempty(find(shot_mg3_list==shot))
            [wdia,x1,t1,d,e]=rda_eff(shot,'ppf','efit/wdia');
          else
            [wdia,x1,t1,d,e]=rda_eff(shot,'ppf','mg3/wpd');
            wdia=interp1(t1,wdia,t);
          end
          [rgeo,x3,t3,d,e]=rda_eff(shot,'ppf','efit/rgeo');
          [cr0,x3,t3,d,e]=rda_eff(shot,'ppf','efit/cr0');
          [bvac,x3,t3,d,e]=rda_eff(shot,'ppf','efit/bvac');
          [volm,x3,t3,d,e]=rda_eff(shot,'ppf','efit/volm');
          a=56.605.*wdia.*cr0.*rgeo./xip./volm./bvac;
        end

      case {'LIDR/Z','lidr/z','Lidr/Z','LIDR/Z?uid=jetppf+seq=0'}
        % 1D but vs R instead of t
        x=t;
        t=[];
        
      end
    
    trace.data=a;
    trace.x=x;
    trace.t=t;
    clear error
    error=e;
    if length(size(trace.data))==1 | (length(size(trace.data))==2 & size(trace.data,2)==1)
      trace.dim=[{trace.t}];
      trace.dimunits={'time [s]'};
    elseif length(size(trace.data))==2
      trace.dim=[{trace.x} ; {trace.t}];
      trace.dimunits=[{'R [m] or rho=sqrt(psi_norm)'} ; {'time [s]'}];
    else
      disp('how to deal with 3D arrays?')
      trace.dim=[{trace.x} ; {trace.t} ; {d}];
      trace.dimunits=[{'R [m] or rho=sqrt(psi_norm)'} ; {'time [s]'} ; {'d'}];
      trace.d=d;
    end
    trace.name=[ppftype '/' num2str(shot) '/' tracename];
    
  %&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  case KSTARkeywrdall{KSTARsig.iqrho}
    %  q profile on sqrt(psi_norm)
    ppftype='ppf';
    if i_efitm
      tracename=['eftm/q' name_ext];
    else
      tracename=['efit/q' name_ext];
    end
    [a,x,t,d,e]=rda_eff(shot,ppftype,tracename);
    trace.data=a;
    trace.x=sqrt(x); % x is psi (? to test)
    trace.t=t;
    trace.dim=[{trace.x} ; {trace.t}];
    trace.dimunits=[{'sqrt(\psi)'} ; {'time [s]'}];
    trace.name=[ppftype '/' num2str(shot) '/' tracename];
    error=e;

  %&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  case KSTARkeywrdall{KSTARsig.idelta}
    %  average of delatop and deltabot
    ppftype='ppf';
    tracename1=['efit/triu' name_ext];
    tracename2=['efit/tril' name_ext];
    [a1,x,t,d,e]=rda_eff(shot,ppftype,tracename1);
    [a2,x,t,d,e]=rda_eff(shot,ppftype,tracename2);
    trace.data=0.5.*(a1+a2);
    trace.x=x;
    trace.t=t;
    trace.dim=[{trace.t}];
    trace.dimunits=[{'time [s]'}];
    trace.name=[ppftype '/' num2str(shot) '/efit/0.5(triu+tril)'];
    error=e;

  %&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  case {KSTARkeywrdall{KSTARsig.ine} , KSTARkeywrdall{KSTARsig.ite}}
    %  ne, te raw data from LIDR vs R,t. Add error bars
    ppftype='ppf';
    if strcmp(KSTARkeywrdcase{index},KSTARkeywrdall{KSTARsig.ine})
      tracename=['LIDR/NE' name_ext];
    else
      tracename=['LIDR/TE' name_ext];
    end
    [a,x,t,d,e]=rda_eff(shot,ppftype,tracename);
    trace.data=a;
    trace.x=x;
    trace.t=t;
    trace.dim=[{trace.x} ; {trace.t}];
    trace.dimunits=[{'R [m]'} ; {'time [s]'}];
    trace.std=[];
    trace.name=[ppftype '/' num2str(shot) '/' tracename];
    error=e;

  %&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  case {KSTARkeywrdall{KSTARsig.inerho} , KSTARkeywrdall{KSTARsig.iterho}}
    %  ne, te on rho mesh. use lid2, thus need chain2 to have been run. Add error bars
    ppftype='ppf';
    if strcmp(KSTARkeywrdcase{index},KSTARkeywrdall{KSTARsig.inerho})
      tracename=['LID2/NEO' name_ext];
    else
      tracename=['LID2/TEO' name_ext];
    end
    [a,x,t,d,e]=rda_eff(shot,ppftype,tracename);
    trace.data=a;
    trace.x=x;
    trace.t=t;
    trace.dim=[{trace.x} ; {trace.t}];
    trace.dimunits=[{'rho=sqrt(psi)'} ; {'time [s]'}];
    trace.std=[];
    trace.name=[ppftype '/' num2str(shot) '/' tracename];
    error=e;

  %&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  case {'sxr','sxR'}
    %  LOAD MULTI CHANNEL DATA    
    %  load KSTAR soft x-ray data 
    % parameters needed for correct convertion of KSTAR Sxr data
    vconvert=   [1.379 1.311 1.249 1.191 1.139 1.093 1.049 ...
          1.011 0.975 0.945 0.917 0.893 0.873 0.856 ...
          0.842 0.829 0.821 0.815 0.821 0.829 0.842 ...
          0.856 0.873 0.894 0.918 0.946 0.976 1.012 ...
          1.050 1.094 1.141 1.193 1.251 1.313 1.382];
    rconvert= [3.45 3.43 3.41 3.37 3.33 3.28 3.23 3.18 3.14 ...
          3.09 3.05 3.00 2.94 2.89 2.83 2.77 2.72 2.68 2.63 ...
          2.59 2.55 2.49 2.44 2.40 2.37 2.33 2.29 2.26 2.23 ...
          2.19 2.14 2.12 2.10 2.08 2.06];
    if  nargin>=3 & ~isempty(varargin{1})
      starti=varargin{1}(1);
      endi=varargin{1}(2);
    else
      starti=1;
      endi=24;
    end
    if  nargin>=4 & ~isempty(varargin{2})
      status=varargin{2};
    else
      status=ones(endi-starti+1,1);
    end
    trace.t=[];
    trace.x=[];
    iloaded_data=0;
    for i=starti:endi
      % Read channels from lowchannel to upchannel if necessary
      if status(i)==1
        iloaded_data=iloaded_data+1;
        % Status=1 => Not Read Yet
        % vertical SXR chords
        ppftype='jpf';
        tracename=['db/j3-sxr<v' num2str(i) '/1' name_ext];
        if shot<48000
          tracename=['db/j3-sxr<t' num2str(i) '/1' name_ext];
          disp('Using T camera: Radius data probably wrong')
        end
        a=which('jpfdat');
        if isempty(a)
          [a,x,t,d,e]=rda_eff(shot,ppftype,tracename);
          % Convert from raw sxr data to W/m^2
          % EDIT: on KSTAR a is not empty on error
          if ~isempty(a)
            if ~isempty(t)
              trace.data(i,:) = a * vconvert(i);
              trace.t=t;
              if ~isempty(x)
                trace.x(i,:)=x; 
              end
            end
            error=e;
          end  
        else
          disp(['Reading channel ' tracename]);
          [a, t, nwds, title, unit, ier] = jpfdat(tracename, shot);
          if ~ier
            % Convert from raw sxr data to W/m^2
            trace.data(i,:) = a' * vconvert(i);
            trace.t=t';
          end
        end
        trace.dim=[{[starti:endi]'} ; {trace.t}];
        trace.dimunits=[{'channels'} ; {'time [s]'}];
        trace.name=[ 'jpf/' num2str(shot) '/' 'db/j3-sxr<vXX' '/1' name_ext];
      end
    end
    if isempty(trace.t)
      disp(['no data in ' trace.name])
      return
    end
  % calculating intersection of the view lines with magnetics axis 
  if strcmp(data_type_eff_noext,'sxR')
    if iloaded_data>0
      if nargin>=5 & ~isempty(varargin{3})
        zmag=varargin{3};
      else
        zmag=loadKSTARdata(shot,'zmag');
      end
      zmageff=interp1(zmag.t,zmag.data,trace.t);
      for i=starti:endi
        radius.data(i,:)=2.848 + (2.172-zmageff') .* tan(-5.0/180.*3.14159 - atan2(0.99.*(i-18),35.31));
      end
      iii=0;
      if nargin>=8 & ~isempty(varargin{6})
        iii=str2num(varargin{6});
      end
      if iii==1
        for i=starti:endi
          radius.data(i,:)=rconvert(i);
        end
        disp('uses B. Alper fixed R array for SXR R intersection')
      end
      radius.t=t;
      varargout{1}={radius}; 
      trace.R=radius.data;
    else
      varargout{1}={struct([])};
      trace.R=[];
    end
  end

  %&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
  case 'ece'
    if  nargin>=3 & ~isempty(varargin{1})
      starti=varargin{1}(1);
      endi=varargin{1}(2);
    else
      starti=1;
      endi=24;
    end
    if nargin>=4 & ~isempty(varargin{2})
      status=varargin{2};
    else
      status=ones(endi,1);
    end
    % Read channels from lowchannel to upchannel if necessary     
    for i=starti:endi
      if status(i)==1
        % ECE, te0
        % Status=1 => Not Read Yet
        ppftype='ppf';
        tracename=['kk3/te' num2str(i,'%2.2d') name_ext];
        disp(tracename)
        a=which('ppfread');
        if isempty(a) | ~isempty(name_ext)
          [a,x,t,d,e]=rda_eff(shot,ppftype,tracename);
          if isempty(a) & size(trace.data,2)>1
            trace.data(i,:)=NaN;
          else
            trace.data(i,:)=a;
            trace.t=t;
          end
          if ~isempty(x); trace.x(i,:)=x'; end;
          error=e;
        else
          [a,x,t,unitd,unitx,unitt,comment,sequence,e]= ...
              ppfread(shot,'KK3',['TE' num2str(i,'%2.2d')]);
          if isempty(a) & size(trace.data,2)>1
            trace.data(i,:)=NaN;
          else
            trace.data(i,:)=a';
            trace.t=t';
          end
          if ~isempty(x); trace.x(i,:)=x; end;
          error=e;
        end
        
        ppftypeR='ppf';
        tracenameR=['kk3/rc' num2str(i,'%2.2d') name_ext];
        a=which('ppfdat');
        if isempty(a) | ~isempty(name_ext)
          [a,x,t,d,e]=rda_eff(shot,ppftypeR,tracenameR);
          if isempty(a) & size(trace.data,2)>1
            radius.data(i,:)=NaN;
          else
            radius.data(i,:)=a;
            radius.t=t;
            radius.x=x;
          end
        else
          [a,x,t,unitd,unitx,unitt,comment,sequence,e]= ...
              ppfread(shot,'KK3',['RC' num2str(i,'%2.2d')]);
          if isempty(a) & size(trace.data,2)>1
            radius.data(i,:)=NaN;
          else
            radius.data(i,:)=a';
            radius.t=t';
            radius.x=x';
          end
        end
      end
    end 
    trace.dim=[{[starti:endi]'} ; {trace.t}];
    trace.dimunits=[{'channels'} ; {'time [s]'}];
    trace.name=[ 'ppf/' num2str(shot) '/' 'kk3/teXX' name_ext ];
    if exist('radius')
      varargout={{radius}}; 
      for i=starti:endi
        trace.R(i,:)=interp1(radius.t,radius.data(i,:),trace.t);
      end
    else
      varargout={{struct([])}};
      trace.R=[];
    end

  otherwise
    disp('case not yet defined')
    
end