0001 function [fluct_out] = fitfluct_yp(fluct_in,mode,method,ngrid,nharm)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 if nargin == 1,
0021 mode = 1;
0022 method = 'pchip';
0023 ngrid = 1001;
0024 nharm = [];
0025 end
0026 if nargin == 2,
0027 method = 'pchip';
0028 ngrid = 1001;
0029 nharm = [];
0030 end
0031 if nargin == 3,
0032 ngrid = 1001;
0033 nharm = [];
0034 end
0035 if nargin == 4,
0036 nharm = [];
0037 end
0038
0039 srho = linspace(0,1,ngrid).^2;
0040 lrho = length(fluct_in.rho);
0041 mtheta = length(fluct_in.theta);
0042 nphi = length(fluct_in.phi);
0043
0044 nharm = length(fluct_in.theta) - 1;
0045
0046 field_name = fieldnames(fluct_in);
0047
0048 test_field_name_ne = strfind(field_name,'ne');
0049 test_field_name_B = strfind(field_name,'B');
0050 flag_naequilp_fluct = 0;
0051 for i = 1:length(field_name),
0052 if ~isempty(test_field_name_ne{i}) | ~isempty(test_field_name_B{i}), flag_naequilp_fluct = flag_naequilp_fluct + 1;end
0053 end
0054
0055 for i = 1:length(field_name),
0056 if isfield(fluct_in,field_name(i)),
0057 if isstruct(fluct_in.(char(field_name(i)))) && isempty(strfind(char(field_name(i)),'fitparam')) && isempty(strfind(char(field_name(i)),'npar0_lh')),
0058 for istruct = 1:length(fluct_in.(char(field_name(i)))),
0059 subfield_name = fieldnames(fluct_in.(char(field_name(i))));
0060
0061 for j = 1:length(subfield_name),
0062 if strcmp(char(subfield_name{j}(1)),'phase') || strcmp(char(subfield_name{j}(1)),'X'),
0063 if mode == 1,
0064 if size(fluct_in.(char(field_name(i))),1) == lrho && size(fluct_in.(char(field_name(i))),2) == mtheta && size(fluct_in.(char(field_name(i))),3) == nphi,
0065
0066 elseif size(fluct_in.(char(field_name(i)))(istruct).(char(subfield_name(j))),1) == lrho && size(fluct_in.(char(field_name(i)))(istruct).(char(subfield_name(j))),2) == mtheta && size(fluct_in.(char(field_name(i)))(istruct).(char(subfield_name(j))),3) == 1,
0067 fluct_out.([char(field_name(i)),'_fit'])(istruct).([char(subfield_name(j)),'_fit']) = interpequilpt_yp(method,interp1(fluct_in.rho,fluct_in.(char(field_name(i)))(istruct).(char(subfield_name(j))),srho,method),srho,fluct_in.theta,nharm);
0068 elseif size(fluct_in.(char(field_name(i)))(istruct).(char(subfield_name(j))),1) == lrho && size(fluct_in.(char(field_name(i)))(istruct).(char(subfield_name(j))),2) == 1 && size(fluct_in.(char(field_name(i)))(istruct).(char(subfield_name(j))),3) == 1,
0069 fluct_out.([char(field_name(i)),'_fit'])(istruct).([char(subfield_name(j)),'_fit']) = interpequilpt_yp(method,interp1(fluct_in.rho,fluct_in.(char(field_name(i)))(istruct).(char(subfield_name(j))),srho,method),srho);
0070
0071
0072 end
0073 else
0074 error('Mode 2 (x,y,phi) not yet implemented in fitfluct_yp.m');
0075 end
0076 else
0077 fluct_out.([char(field_name(i)),'_fit'])(istruct).([char(subfield_name(j))]) = fluct_in.(char(field_name(i)))(istruct).(char(subfield_name(j)));
0078 end
0079 end
0080 end
0081 else
0082 if strcmp(char(field_name{i}(1)),'x') || strcmp(char(field_name{i}(1)),'X'),
0083 if flag_naequilp_fluct,
0084 if size(fluct_in.(char(field_name(i))),1) == lrho && size(fluct_in.(char(field_name(i))),2) == mtheta && size(fluct_in.(char(field_name(i))),3) == nphi,
0085
0086 elseif size(fluct_in.(char(field_name(i))),1) == lrho && size(fluct_in.(char(field_name(i))),2) == mtheta && size(fluct_in.(char(field_name(i))),3) == 1,
0087 fluct_out.([char(field_name(i)),'_fit']) = interpequilpt_yp(method,interp1(fluct_in.rho,fluct_in.(char(field_name(i))),srho,method),srho,fluct_in.theta,nharm);
0088 elseif size(fluct_in.(char(field_name(i))),1) == lrho && size(fluct_in.(char(field_name(i))),2) == 1 && size(fluct_in.(char(field_name(i))),3) == 1,
0089 fluct_out.([char(field_name(i)),'_fit']) = interpequilpt_yp(method,interp1(fluct_in.rho,fluct_in.(char(field_name(i))),srho,method),srho);
0090 end
0091 end
0092 else
0093 if ~strcmp(char(field_name(i)),'rho') && ~strcmp(char(field_name(i)),'theta') && ~strcmp(char(field_name(i)),'phi')
0094 if strcmp(char(field_name(i)),'npar0_lh') || strcmp(char(field_name(i)),'id'),
0095 fluct_out.(char(field_name(i))) = fluct_in.(char(field_name(i)));
0096 else
0097 if flag_naequilp_fluct,
0098 fluct_out.(char(field_name(i))) = fluct_in.(char(field_name(i)));
0099 if strcmp(char(field_name(i)),'equil_id'),fluct_out.method = method;end
0100 end
0101 end
0102 end
0103 end
0104 end
0105 end
0106 end
0107
0108
0109
0110
0111