📄 matlab2fmex.m
字号:
%Inputs first.inoutother=cell(4,1);temp=find(funstr{1}=='(');if ~isempty(temp) dummy=find(funstrwords_b{1}>temp(1)); for j=1:length(dummy), inoutother{1}(j)=funstrwords{1}(dummy(j)); endelse error('you have to have some inputs');endinoutother{1}=inoutother{1}';%Outputs nexttemp=find(funstr{1}=='=');if ~isempty(temp) dummy=find(funstrwords_b{1}<temp(1)); for j=2:length(dummy), inoutother{2}(j-1)=funstrwords{1}(dummy(j)); endelse error('you have to have some outputs');endinoutother{2}=inoutother{2}';%Now other vars from cwtemp=fieldnames(cw);count=1;for i=1:length(temp) if ((~isin(temp(i),inoutother{1}))&(~isin(temp(i),inoutother{2}))) inoutother{3}(count)=temp(i); count=count+1; endendinoutother{3}=inoutother{3}';%And other things I don't want to be counted as regular varsinoutother{4}(1)={'lhs'};inoutother{4}(2)={'rhs'};inoutother{4}(3)={'nlhs'};inoutother{4}(4)={'nrhs'};count=5;for i=1:length(inoutother{1}) if ~isreal(getfield(cw,inoutother{1}{i})) inoutother{4}(count)={[inoutother{1}{i},'_r']}; inoutother{4}(count+1)={[inoutother{1}{i},'_i']}; count=count+2; endendfor i=1:length(inoutother{2}) if ~isreal(getfield(cw,inoutother{2}{i})) inoutother{4}(count)={[inoutother{2}{i},'_r']}; inoutother{4}(count+1)={[inoutother{2}{i},'_i']}; count=count+2; endendinoutother{4}=inoutother{4}';if length(inoutother{3})>0 inoutother3={inoutother{1}{:},inoutother{2}{:},inoutother{3}{:}};else inoutother3={inoutother{1}{:},inoutother{2}{:}};end%we need to decide whether the local vars are complex, real, or integer.localvartype=cell(length(inoutother{3}),1);for i=1:length(inoutother{3}) if ~isreal(getfield(cw,inoutother{3}{i})) localvartype{i}='complex'; elseif islogical(getfield(cw,inoutother{3}{i})) localvartype{i}='logical'; else if nnz(getfield(cw,inoutother{3}{i})~=round(getfield(cw,inoutother{3}{i})))>0 localvartype{i}='real'; else if want_in==1 localvartype{i}='integer'; else localvartype{i}='real'; end end endend%Let's decide whether this routine is recursive or not.recursive=0;for i=1:s temp=strcmp(filename,funstrwords{i}); if any(temp)&~strcmp(funstrwords{i}{1},'function') temp1=findstr('%',funstr{i}); if isempty(temp1) recursive=1; else temp2=find(temp); if funstrwords_b{i}(temp2(1))<temp1(1) recursive=1; end end endend% So, now we start the macros to changeover.tickercount=1;pticker=0;%First, get rid of the first line of function definition.for i=1:s-1 funstr{i}=funstr{i+1};end funstr={funstr{1:s-1}}';updatefunstr;%Save all the original stuff for shape determination later.funstr1=funstr;funstrnumbers1=funstrnumbers;funstrnumbers_b1=funstrnumbers_b;funstrnumbers_e1=funstrnumbers_e;funstrwords1=funstrwords;funstrwords_b1=funstrwords_b;funstrwords_e1=funstrwords_e;%Put a decimal point on many numbers which have none.%try fprintf(1,' ');pticker=pticker+1; if want_fb&(~want_kb),fprintf(1,' putting decimal points etc. ....................... 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 fid=0; for j=gotto2:length(funstrnumbers{i}) if count==0 goon=1; temp1=inmlcall(i,funstrnumbers_b{i}(j),funstr,funstrwords,funstrwords_b); [temp2,howmany2,subscripts2,centercomma2,parens2]=inwhichlast(i,funstrnumbers_b{i}(j));% funstr{i},funstrnumbers_b{i}(j),funstr{i}(1:funstrnumbers_b{i}(j)),temp2,'ddddddddddddddd2',kb temp3=0; if temp2==1 %In bracket last [temp3,howmany,subscripts,centercomma,parens,foo]=inwhichlast(i,parens2(1)); if ~(parens(1)==fid) tempstr=makeMATLABcallstring(1,{funstr{i}(parens2(1):parens2(2))},[],parens2,i,j); fid=parens(1); end if temp3==2 %In subscript ;%don't add if is a bracket in a subscript goon=0; end%%% if any(strcmp(funstrwords{i},'reshape'))%%% funstr{i},tempstr,'ddddddddddddddd3',kb%%% end if any(strcmp(tempstr(1),typs{7})) % We have a bracketed expression full of integers goon=0; end end %%% if any(strcmp(funstrnumbers{i},'1.0'))%%% funstr{i},funstr{i}(1:funstrnumbers_b{i}(j)),goon,'ddddddddddddddd2',kb%%% end if goon|temp1 if temp2==5|temp2==6|temp3==5|temp3==6 %In intrinsics last temp5=find(funstrwords_b{i}<parens2(1)); if ~isempty(temp5) temp5=temp5(end); if temp3==5 temp5=foo; end if any(strcmp(funstrwords{i}{temp5},{'sum';'reshape';'min';'max';'size';'prod';'mean';'dot'})) %Don't need them on dimensions for some [howmany3,subscripts3,centercomma3,parens3]=hassubscript(i,temp5); if howmany3>1 if funstrnumbers_b{i}(j)>centercomma3(1) & funstrnumbers_b{i}(j)<parens3(2) goon=0; if length(funstrnumbers{i}{j})>1 if strcmp(funstrnumbers{i}{j}(end-1:end),'.0') %Remove .0 from these places funstr{i}=[funstr{i}(1:funstrnumbers_e{i}(j)-2),funstr{i}((funstrnumbers_e{i}(j)+1):(end))]; updatefunstr(i); count=1;gotto=i;gotto2=j+1; end end end end end end end%%% if any(strcmp(funstrnumbers{i},'1.0'))%%% funstr{i},goon,j,temp2,temp1,kb%%% end if goon if temp2==0|temp2==1|temp2==4|temp2==5|temp2==6|temp1 if ~any(strcmp({'for';'while'},funstrwords{i}{1}))%%% if length(find(findstr(funstrnumbers{i}{j},'.')))==0%funstr{i},funstrnumbers{i}{j},intersect([typs{17}{:}],funstrnumbers{i}{j})if length(intersect([typs{17}{:}],funstrnumbers{i}{j}))==0 funstr{i}=[funstr{i}(1:(funstrnumbers_e{i}(j))),'.0',funstr{i}((funstrnumbers_e{i}(j)+1):(end))]; updatefunstr(i); count=1;gotto=i;gotto2=j+1; %funstr{i},kbend%%% end end end end end%%% if any(strcmp(funstrwords{i},'reshape'))%%% funstr{i},tempstr,'ddddddddddddddd4',kb%%% 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 with putting decimal points etc.'),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%Changed bracketed expressions%try fprintf(1,' ');pticker=pticker+1; if want_fb&(~want_kb),fprintf(1,' fixing bracketed assignments ...................... 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 if count==0; temp=findstr('[',funstr{i}); fid=0; if ~isempty(temp) for k=1:length(temp) if count==0 temp=findstr('[',funstr{i}); temp=temp(k); temp1=findrights(temp,funstr{i}); goon=find(funstrwords_b{i}(funstrwords_b{i}<temp)); goonimag=0; % funstr{i},'stoppppppppp222222',kb if isempty(goon) goonimag=0;% funstr{i},'stoppppppppp',kb else if temp>4 goonimag=(~(strcmp('spread(',funstr{i}(temp-4:temp-1)))&(length(find(strcmpi('int',funstrwords{i}{goon(length(goon))})))==0)&(length(find(strcmp('reshape',funstrwords{i}{goon(length(goon))})))==0)&(length(find(strcmp('disp',funstrwords{i}{1})))==0)); else goonimag=((length(find(strcmpi('int',funstrwords{i}{goon(end)})))==0)&(length(find(strcmp('reshape',funstrwords{i}{goon(end)})))==0)&(length(find(strcmp('disp',funstrwords{i}{1})))==0)); end end if (goonimag) temp2=1;%temp2=commas/spaces temp3=1;%temp3=m-size for j=(temp+1):(temp1-1) if strcmp(funstr{i}(j),' ') if ((~insubscript(i,temp))|(inwhichlast(i,j)==1)) if ((~isspace(funstr{i}(j-1)))&(~strcmp(funstr{i}(j-1),','))&(~strcmp(funstr{i}(j+1),','))&(~strcmp(funstr{i}(j-1),'['))&(~strcmp(funstr{i}(j+1),']'))) temp2=temp2+1; funstr{i}(j)=','; end end elseif strcmp(funstr{i}(j),',') if ~insubscript(i,j,temp,temp1) temp2=temp2+1; end end if strcmp(funstr{i}(j),';') fid=1; temp2=1; temp3=temp3+1; funstr{i}(j)=','; end end if fid if ~insubscript(i,temp) funstr{i}=[funstr{i}(1:(temp-1)),'reshape(',funstr{i}(temp:temp1),',[',num2str(temp2),',',num2str(temp3),']).''',funstr{i}((temp1+1):end)];count=1;gotto=i; else funstr{i}=[funstr{i}(1:(temp-1)),'[transpose(reshape(',funstr{i}(temp:temp1),',[',num2str(temp2),',',num2str(temp3),']))]',funstr{i}((temp1+1):end)];count=1;gotto=i; end else [outflag,howmany,subscripts,centercomma,parens]=inwhichlast(i,temp); %funstr{i},kb tempstr=0; if outflag==5 temp4=find(~isspace(funstr{i})); temp4=temp4(temp4<parens(1)); temp4=temp4(end); temp5=find(funstrwords_e{i}==temp4(end)); if ~isempty(temp5) if any(strcmp(funstrwords{i}{temp5},{'logical'})) tempstr=1; end end end %if ((~insubscript(i,temp))&(~inbracket(i,temp,funstr))&~(strcmp('[',funstr{i}(1)))) if outflag==0|tempstr if ((strcmp(funstrwords{i}{1},'disp'))|(strcmp(funstrwords{i}{1},'for'))|(strcmp(funstrwords{i}{1},'call'))) funstr{i}=[funstr{i}(1:(temp-1)),funstr{i}(temp+1:temp1-1),funstr{i}((temp1+1):end)];count=1;gotto=i; else if ~any(':'==funstr{i}(temp:temp1)) %funstr{i} funstr{i}=[funstr{i}(1:(temp-1)),'spread(',funstr{i}(temp:temp1),',1,1)',funstr{i}((temp1+1):end)];count=1;gotto=i; %'[[[[[[[[[[[[[[[',funstr{i},kb end end else %Do nothing end end if count==1 updatefunstr(i); end end end end end end end end if want_kb,disp('finished fixing bracketed assignments'),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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -