⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 matlab2fmex.m

📁 student teacher and proferssor llove this project,this a very important exmple
💻 M
📖 第 1 页 / 共 5 页
字号:
%Changed non-integral expressions in subscripts%try fprintf(1,' ');pticker=pticker+1; if want_fb&(~want_kb),fprintf(1,' fixing bracketed assignments II ................... 1');end count=1;gotto=1;gotto2=1; while count==1  count=0;  for i=gotto:s   fprintf(1,b);fprintf(1,ticker{tickercount});   tickercount=tickercount+1;if tickercount>11, tickercount=1; end   if i==s, fprintf(1,b);fprintf(1,ticker{pticker}); end   for j=gotto2:length(funstrwords{i})    if count==0     if (length(find(strcmp(funstrwords{i}(j),inoutother3)))>0)      if insubscript(i,funstrwords_b{i}(j))       [temp2,howmany2,subscripts2,centercomma2,parens2]=inwhichlast(i,funstrwords_b{i}(j));       if ((temp2==1)|(temp2==2))	goon=1;	if temp2==1	 [outflag,howmany,subscripts,centercomma,parens]=inbracket(i,funstrwords_b{i}(j),funstr);	 if howmany>=3	  goon=0;	 end	end	if length(find(strcmp(funstrwords{i}{j},inoutother{3})))>0	 temp1=find(strcmp(funstrwords{i}{j},inoutother{3}));	 if strcmp(localvartype{temp1},'integer')	  goon=0;	 end	end	if funstrwords_b{i}(j)>4	 if strcmp(funstr{i}(funstrwords_b{i}(j)-4:funstrwords_b{i}(j)-1),'int(')	  goon=0;	 end	end        %Which subscript are we in?        if howmany2==1         fid=1;        elseif howmany2==2         if ((funstrwords_b{i}(j)>parens2(1))&(funstrwords_b{i}(j)<centercomma2))          fid=1;         else,          fid=2;         end        end        for k=1:length(loglist)         temp3=findstrexact(loglist{k},subscripts2{fid});         if ~isempty(temp3)          temp4=findstrexact(subscripts2{fid},funstr{i});          for temp=1:length(temp3)           [outflag,howmany,subscripts,centercomma,parens]=inwhichlast(i,temp4+temp3(temp)-1);           if ~isempty(parens)            if parens(1)==parens2(1) %parens we are in match parens that relop is in             goon=0;            end           end          end         end        end	if goon==1	 [howmany,subscripts,centercomma,parens]=hassubscript(i,j);	 if howmany==0	  funstr{i}=[funstr{i}(1:funstrwords_b{i}(j)-1),'int(',funstrwords{i}{j},')',funstr{i}(funstrwords_e{i}(j)+1:end)];	 else	  funstr{i}=[funstr{i}(1:funstrwords_b{i}(j)-1),'int(',funstr{i}(funstrwords_b{i}(j):parens(2)),')',funstr{i}(parens(2)+1:end)];	 end	 if length(find(strcmp('int',fortranfunwords)))==0	  fortranfunwords{length(fortranfunwords)+1}='int';	 end	 updatefunstr(i);	 count=1;gotto=i;gotto2=j+1;	end       end      end     end    end    if count==1, break; end   end   if count==0, gotto2=1; end   if count==1, break; end  end end if want_kb,disp('finished fixing bracketed assignments II'),disp(r),showall(funstr),disp(r),keyboard,end if want_fb&(~want_kb),fprintf(1,' finished \n');end%%%catch%%% disp(r);disp(funstr{i});disp(['line number ',num2str(i)]);disp(lasterr);disp(r);%%% disp('Conversion error in preceeding line.');%%% disp('Try to continue? [y,<return>]');%%% tempans=input('or enter keyboard mode? [n,k]','s');%%% if ~isempty(tempans), if ((strcmp(tempans,'n'))|(strcmp(tempans,'k'))), keyboard, end, end%%%end%Change things about the math (matrix mult, /, .*, +, etc.), in cell 'operators'.%try fprintf(1,' ');pticker=pticker+1; if want_fb&(~want_kb),fprintf(1,' operator changeover ............................... 1');end for j=1:length(operators)  gotto=1;count=1;  while count==1   count=0;   for i=gotto:s    fprintf(1,b);fprintf(1,ticker{tickercount});    tickercount=tickercount+1;if tickercount>11, tickercount=1; end    if i==s, fprintf(1,b);fprintf(1,ticker{pticker}); end    dummy=findstr(operators{j,1},funstr{i});    if ~isempty(dummy)     for k=1:length(dummy)      temp=dummy(k);      if ~strcmp(funstrwords{i}{1},'error')&~strcmp(funstrwords{i}{1},'print')       goon=1;       if strcmp(funstrwords{i}{1},'disp')	temp1=find(''''==funstr{i});	if ~isempty(temp1)	 if ((temp==temp1(1))|(temp==temp1(end)))	  goon=0;	 end	end       end       if strcmp(funstr{i}(temp-1),'.'), goon=0; end       if strcmp(funstr{i}(temp-1),'*'), goon=0; end       if strcmp(funstr{i}(temp+length(operators{j,1})),'*')&strcmp('*',operators{j,1})        goon=0;       end       if goon	goonimag=0;	if ((want_op==1)|(~((strcmp(operators{j,1},'+'))|(strcmp(operators{j,1},'-')))))         [temp1,temp2]=changeoperator(i,operators{j,1},temp);	 if temp1          updatefunstr(i);	 end	 if ((want_op==1)|(length(temp2{1}>0))|(temp1==1))	  updatefunstr(i);%	  if tempflag==0	   if length(temp2{1}>0)	    if length(findstr(temp2{1},mexoperatorinterfaces{1}))==0	     mexoperatorinterfaces{1}=[mexoperatorinterfaces{1} temp2{1}];	     mexoperatorinterfaces{2}=[mexoperatorinterfaces{2} temp2{2}];	    end	   end%	  end	  count=1;gotto=i;	 end	end       end      end      if count~=0       break      end     end    end    if count~=0     break    end   end  end end if want_kb,disp('finished with operator changeover'),disp(r),showall(funstr),disp(r),keyboard,end if want_fb&(~want_kb),fprintf(1,' finished \n');end%%%catch%%% disp(r);disp(funstr{i});disp(['line number ',num2str(i)]);disp(lasterr);disp(r);%%% disp('Conversion error in preceeding line.');%%% disp('Try to continue? [y,<return>]');%%% tempans=input('or enter keyboard mode? [n,k]','s');%%% if ~isempty(tempans), if ((strcmp(tempans,'n'))|(strcmp(tempans,'k'))), keyboard, end, end%%%end%Fix subscripts for in/out vars because everything 2-dim now (except in brackets).%try fprintf(1,' ');pticker=pticker+1; if want_fb&(~want_kb),fprintf(1,' making 2 subscripts ............................... 1');end %First make sure everythings has 2 subscripts count=1;gotto=1;gotto2=0; while count==1  count=0;  for i=gotto:s   fprintf(1,b);fprintf(1,ticker{tickercount});   tickercount=tickercount+1;if tickercount>11, tickercount=1; end   if i==s, fprintf(1,b);fprintf(1,ticker{pticker}); end   temp3=length(funstrwords{i});   for j=(temp3-gotto2):-1:1    if ~inastring(funstrwords_b{i}(j),funstr{i})     if count==0      if (length(find(strcmp(funstrwords{i}(j),inoutother3)))>0)       [howmany,subscripts,centercomma,parens]=hassubscript(i,j);       goonimag=0;%set to be just a pack unless goonimag=>1;       temp1=findstr('=',funstr{i});       if ~isempty(temp1) %only test if there is an = sign        temp2=1;        for k=1:length(temp1)         if temp2==1          if ~insubscript(i,temp1(k))           temp2=temp1(k);break          end         end        end        if temp2==1 %No equals sign, goonimag already =0        else %Here, we have a main equals sign, is our word before or after?         if funstrwords_b{i}(j)<temp2 %Need a where statement          goonimag=1;         end        end       end       switch howmany %Number of subscripts for this var        case 0 %Do nothing        case 1         tempstr=makeMATLABcallstring(howmany,subscripts,centercomma,parens,i,j);         fid=need_ss2in(howmany,subscripts,centercomma,parens,i,j,tempstr);         temp=funstr{i}((parens(1)+1):(parens(2)-1));         %Is it before or after the main = sign?         if any(strcmp(tempstr,typs{8}))          if goonimag==0 %Pack           funstr{i}=[funstr{i}(1:(funstrwords_b{i}(j)-1)),'ss2in(',funstrwords{i}{j},',',subscripts{1},')',funstr{i}((parens(2)+1):end)];          else %where           fortranfunwords{length(fortranfunwords)+1}='where';           funstr{i}=['where(',subscripts{1},') ',funstrwords{i}{j},funstr{i}((parens(2)+1):end)];          end          updatefunstr(i);          count=1;gotto=i;gotto2=temp3-j;         else          if goonimag==0 %after main equals sign           if size(getfield(cw,funstrwords{i}{j}),1)==1 %row vector var, test for ss2in            if fid(1) %add a ss2in             funstr{i}=[funstr{i}(1:(funstrwords_b{i}(j)-1)),'ss2in(',funstrwords{i}{j},',',subscripts{1},')',funstr{i}((parens(2)+1):end)];            else %place a 1 there and index normally             funstr{i}=[funstr{i}(1:parens(1)),'1,',funstr{i}((parens(1)+1):end)];            end           elseif size(getfield(cw,funstrwords{i}{j}),2)==1 %column vector var, test for ss2in            if fid(1) %add a ss2in             funstr{i}=[funstr{i}(1:(funstrwords_b{i}(j)-1)),'ss2in(',funstrwords{i}{j},',',subscripts{1},')',funstr{i}((parens(2)+1):end)];            else %place a 1 there and index normally             funstr{i}=[funstr{i}(1:(parens(2)-1)),',1',funstr{i}(parens(2):end)];            end           else            if strcmp(temp(~isspace(temp)),':') %If a colon is the entire subscript, then columnize             fortranfunwords{length(fortranfunwords)+1}='reshape';             fortranfunwords{length(fortranfunwords)+1}='int';             funstr{i}=[funstr{i}(1:(funstrwords_b{i}(j)-1)),'reshape(',funstrwords{i}{j},',[size(',funstrwords{i}{j},'),int(1)])',funstr{i}((parens(2)+1):end)];            else %This should be a ss2in             funstr{i}=[funstr{i}(1:(funstrwords_b{i}(j)-1)),'ss2in(',funstrwords{i}{j},',',subscripts{1},')',funstr{i}((parens(2)+1):end)];            end           end           updatefunstr(i);           count=1;gotto=i;gotto2=temp3-j;          else %subscript on lhs, add 1 if needed                      if size(getfield(cw,funstrwords{i}{j}),1)==1 %row vector var, test for ss2in            funstr{i}=[funstr{i}(1:parens(1)),'1,',funstr{i}((parens(1)+1):end)];           elseif size(getfield(cw,funstrwords{i}{j}),2)==1 %column vector var, test for ss2in            funstr{i}=[funstr{i}(1:(parens(2)-1)),',1',funstr{i}(parens(2):end)];           end           updatefunstr(i);           count=1;gotto=i;gotto2=temp3-j;          end         end        case 2         tempstr=makeMATLABcallstring(howmany,subscripts,centercomma,parens,i,j);         fid=need_ss2in(howmany,subscripts,centercomma,parens,i,j,tempstr);         if goonimag==0 %after main equals sign          if all(fid) %This should not happen ... ?          elseif fid(1) %ss2in only that dim           funstr{i}=[funstr{i}(1:(funstrwords_b{i}(j)-1)),'ss2in(',funstrwords{i}{j},'(:,',subscripts{2},'),',subscripts{1},')',funstr{i}((parens(2)+1):end)];          elseif fid(2)           funstr{i}=[funstr{i}(1:(funstrwords_b{i}(j)-1)),'ss2in(',funstrwords{i}{j},'(',subscripts{1},',:),',subscripts{2},')',funstr{i}((parens(2)+1):end)];          end          if any(fid)&~all(fid)           updatefunstr(i);           count=1;gotto=i;gotto2=temp3-j;          end         end       end %switch      end      %funstr{i},funstrwords{i}{j},kb     end    end    if count==1, break; end   end   if count==0, gotto2=0; end   if count==1, break; end  end end if want_kb,disp('finished with making 2 subscripts'),disp(r),showall(funstr),disp(r),keyboard,end if want_fb&(~want_kb),fprintf(1,' finished \n');end%%%catch%%% disp(r);disp(funstr{i});disp(['line number ',num2str(i)]);disp(lasterr);disp(r);%%% disp('Conversion error in preceeding line.');%%% disp('Try to continue? [y,<return>]');%%% tempans=input('or enter keyboard mode? [n,k]','s');%%% if ~isempty(tempans), if ((strcmp(tempans,'n'))|(strcmp(tempans,'k'))), keyboard, end, end%%%end%Fix logical operators such as &, |, and ~ (and ~= ==> /=)%try fprintf(1,' ');pticker=pticker+1; if want_fb&(~want_kb),fprintf(1,' fixing logical operators .......................... 1');end count=1;gotto=1; while count==1  count=0;  for i=gotto:s   fprintf(1,b);fprintf(1,ticker{tickercount});   tickercount=tickercount+1;if tickercount>11, tickercount=1; end   if i==s, fprintf(1,b);fprintf(1,ticker{pticker}); end   for j=1:size(logicalops,1)    if count==0     temp=findstr(funstr{i},logicalops{j,1});     if ~isempty(temp)      for k=1:size(temp)       if count==0	if strcmp('~',logicalops{j,1})	 temp1=find(~isspace(funstr{i}));	 temp1=temp1(temp1>temp(k));temp1=temp1(1);	 if ~strcmp('=',funstr{i}(temp1))	  funstr{i}=[funstr{i}(1:(temp(k)-1)),logicalops{j,2},funstr{i}((temp(k)+length(logicalops{j,1})):end)];	  updatefunstr(i);	  count=1;gotto=i;	 else	  funstr{i}=[funstr{i}(1:(temp(k)-1)),'/',funstr{i}((temp(k)+length(logicalops{j,1})):end)];	 end	else	 funstr{i}=[funstr{i}(1:(temp(k)-1)),logicalops{j,2},funstr{i}((temp(k)+length(logicalops{j,1})):end)];	 updatefunstr(i);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -