load_externaldata_AUG

PURPOSE ^

SYNOPSIS ^

function external = load_externaldata_AUG(external_in,opt_gui)%(workdir,shotnum,shotime,t1,t2,opt_gui,dummy)

DESCRIPTION ^

 This function loads data from AUG Torbeam output file

 INPUTS : 
   - if nargin == 0, return default external_in to be modified interactively in iload_externaldata_jd

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function external = load_externaldata_AUG(external_in,opt_gui)%(workdir,shotnum,shotime,t1,t2,opt_gui,dummy)
0002 %
0003 % This function loads data from AUG Torbeam output file
0004 %
0005 % INPUTS :
0006 %   - if nargin == 0, return default external_in to be modified interactively in iload_externaldata_jd
0007 
0008 %   - external_in : input structure.
0009 %   - opt_gui     : option for GUI within function (interactive mode only)
0010 %
0011 %
0012 if nargin == 0,
0013     %
0014     % default values
0015     %
0016     [pathname] = igetdir_jd(1,'Please select the directory containing torbeam data',pwd);
0017     %
0018     external.shotnum = 0;
0019     external.shotime = 0;
0020     %
0021     if pathname ~= 0,
0022         %
0023         external.workdir = pathname;
0024         %
0025         flag = 0;
0026         ifilesep = strfind(pathname,filesep);
0027         if length(ifilesep) <= 1 || ifilesep(end) ~= length(pathname),
0028             flag = 1;
0029         else
0030             pathname = pathname(ifilesep(end-1)+1:ifilesep(end)-1);
0031             idatasep = strfind(pathname,'_');
0032             if length(idatasep) <= 1 || idatasep(1) == 1 || idatasep(2) - idatasep(1) == 1,
0033                 flag = 1;
0034             else
0035                 external.shotnum = str2double(pathname(1:idatasep(1)-1));
0036                 external.shotime = str2double(pathname(idatasep(1)+1:idatasep(2)-1));
0037             end
0038         end
0039         if flag == 1,
0040             %
0041             filename = [external.workdir,'topfile'];
0042             %
0043             if exist(filename,'file'),
0044                 fid = fopen(filename);
0045                 data = textscan(fid,'Number of radial and vertical grid points in AUGD:EQH:%d:%f:%f %f %f',1);
0046                 if ~isempty(data{1}),
0047                     external.shotnum = data{1};
0048                 end
0049                 if ~isempty(data{5}),
0050                     external.shotime = data{5};
0051                 end
0052             end
0053         end
0054         %
0055     else
0056         %
0057         external.workdir = pwd;
0058         %
0059     end  
0060     %
0061     %
0062     % description & user halp
0063     %
0064     external.info.workdir = 'directory for source files';
0065     external.info.shotnum = 'Shot number';
0066     external.info.shotime = 'Shot time (s)';
0067     %
0068     % expert mode
0069     %
0070     external.expert.workdir = 0;
0071     external.expert.shotnum = 0;
0072     external.expert.shotime = 0;
0073     %
0074     % range of values
0075     %
0076     external.values.workdir = '';
0077     external.values.shotnum = [0;Inf];
0078     external.values.shotime = [0;Inf];
0079     %
0080     return
0081     %
0082 end
0083 %
0084 if nargin < 2,
0085     opt_gui = false;
0086 end
0087 %
0088 workdir = external_in.workdir;
0089 shotnum = external_in.shotnum;
0090 shotime = external_in.shotime;
0091 %
0092 % ******************************************************************
0093 %
0094 external = '';
0095 basestr = 'AUG';
0096 %
0097 external.basestr = basestr;
0098 external.shotnum = num2str(shotnum);
0099 external.shotime = shotime;
0100 %
0101 filename = [workdir,'ne.dat'];
0102 %
0103 if exist(filename,'file'),
0104     fid = fopen(filename);
0105     data = textscan(fid,'%d',1);
0106     nr = data{1};
0107     data = textscan(fid,'%f %f',nr);
0108     external.equil.prof.ne.rho = data{1};
0109     external.equil.prof.ne.data = data{2}*1e19;
0110     disp('ne data loaded from file')
0111 else
0112     disp('warning : no ne data')
0113 end
0114 %
0115 filename = [workdir,'Te.dat'];
0116 %
0117 if exist(filename,'file'),
0118     fid = fopen(filename);
0119     data = textscan(fid,'%d',1);
0120     nr = data{1};
0121     data = textscan(fid,'%f %f',nr);
0122     external.equil.prof.te.rho = data{1};
0123     external.equil.prof.te.data = data{2}*1e3;
0124     disp('te data loaded from file')
0125 else
0126     disp('warning : no te data')
0127 end
0128 %
0129 external.equil.prof.ti = 1;%Ti/Te
0130 external.equil.prof.zeff = 1.5;%default value
0131 %
0132 filename = [workdir,'topfile'];
0133 %
0134 if exist(filename,'file'),
0135     fid = fopen(filename);
0136     fgetl(fid);
0137     data = textscan(fid,'%d %d',1);
0138     nR = data{1};
0139     nZ = data{2}; 
0140     a = fgetl(fid);
0141     if isempty(a),
0142         fgetl(fid);
0143     end    
0144     fgetl(fid);
0145     fgetl(fid);
0146     data = textscan(fid,'%f',nR);
0147     R = data{1};
0148     a = fgetl(fid);
0149     if isempty(a),
0150         fgetl(fid);
0151     end    
0152     data = textscan(fid,'%f',nZ);
0153     Z = data{1};
0154     a = fgetl(fid);
0155     if isempty(a),
0156         fgetl(fid);
0157     end    
0158     data = textscan(fid,'%f',nR*nZ);
0159     BR = reshape(data{1},nR,nZ);
0160     a = fgetl(fid);
0161     if isempty(a),
0162         fgetl(fid);
0163     end    
0164     data = textscan(fid,'%f',nR*nZ);
0165     Bphi = reshape(data{1},nR,nZ);
0166     a = fgetl(fid);
0167     if isempty(a),
0168         fgetl(fid);
0169     end    
0170     data = textscan(fid,'%f',nR*nZ);
0171     BZ = reshape(data{1},nR,nZ);
0172     a = fgetl(fid);
0173     if isempty(a),
0174         fgetl(fid);
0175     end    
0176     data = textscan(fid,'%f',nR*nZ);
0177     psi = reshape(data{1},nR,nZ)/2/pi;
0178     %
0179     external.equil.shotnum = external.shotnum;
0180     external.equil.shotime = external.shotime;
0181     %
0182     external.equil.magnetic.R = R;
0183     external.equil.magnetic.Z = Z;
0184     external.equil.magnetic.BR = BR;
0185     external.equil.magnetic.BZ = BZ;
0186     external.equil.magnetic.Bphi = Bphi;
0187     external.equil.magnetic.psi = psi;
0188     disp('magnetic equil data loaded from file')
0189 else
0190     disp('warning : no magnetic equil data')
0191 end
0192 %
0193 % waves
0194 %
0195 filenames = dir([workdir,'inbeam*.dat']);
0196 %
0197 for ifile = 1:length(filenames),
0198     fid = fopen([workdir,filenames(ifile).name]);
0199     searchstr = 'Beam';
0200     a = '';
0201     while ~any(strfind(a,searchstr)),
0202         a = fgetl(fid);
0203     end
0204     data = textscan(fid,'%s = %f,',1);
0205     external.wave.(['EC_',num2str(ifile)]).mmode = - data{2};
0206     %
0207     data = textscan(fid,'%s = %f,',1);
0208     external.wave.(['EC_',num2str(ifile)]).f_GHz = data{2}/1e9;
0209     %
0210     data = textscan(fid,'%s = %f,',1);
0211     external.wave.(['EC_',num2str(ifile)]).alpha_L = pi + data{2}*pi/180;
0212     %
0213     data = textscan(fid,'%s = %f,',1);
0214     external.wave.(['EC_',num2str(ifile)]).beta_L = pi/2 + data{2}*pi/180;
0215     %
0216     data = textscan(fid,'%s = %f,',1);
0217     external.wave.(['EC_',num2str(ifile)]).R_L = data{2}/1e2;
0218     %
0219     a = fgetl(fid);
0220     if isempty(a),
0221         fgetl(fid);
0222     end    
0223     %
0224     data = textscan(fid,'%s = %f,',1);
0225     external.wave.(['EC_',num2str(ifile)]).Z_L = data{2}/1e2;
0226     %
0227     a = fgetl(fid);
0228     if isempty(a),
0229         fgetl(fid);
0230     end    
0231     a = fgetl(fid);
0232     a = fgetl(fid);
0233     a = fgetl(fid);
0234     %
0235     data = textscan(fid,'%s = %f,',1);
0236     external.wave.(['EC_',num2str(ifile)]).P_MW = data{2};
0237     %
0238     disp('ECRH data loaded from file')
0239 end
0240 if isempty(filenames),
0241     disp('warning : no ECRH data')
0242 end
0243 %
0244 external.id = [basestr,'_',shotnum,'_',shotime]; 
0245 %
0246 if isnan_jd(external,0),
0247     disp('Warning : NaNs were found in the structure ''external'' : ')
0248     isnan_jd(external,1),
0249 end
0250 %

Community support and wiki are available on Redmine. Last update: 18-Apr-2019.