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

📄 matlab2fmex.m

📁 student teacher and proferssor llove this project,this a very important exmple
💻 M
📖 第 1 页 / 共 5 页
字号:
	 count=1;gotto=i;	end       end      end     end    end   end  end end if want_kb,disp('finished fixing logical operators'),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 all subscripts, possibly add mxi%try fprintf(1,' ');pticker=pticker+1; if want_fb&(~want_kb),fprintf(1,' subscript vectorizing ............................. 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=length(funstrwords{i}):-1:1    if count==0     if (length(find(strcmp(funstrwords{i}(j),inoutother3)))>0)      [howmany,subscripts,centercomma,parens]=hassubscript(i,j);      if howmany==2       tempstr=makeMATLABcallstring(howmany,subscripts,centercomma,parens,i,j);       if any(strcmp(tempstr(1),typs{12})),temp3(1)=0;else temp3(1)=1;end       if any(strcmp(tempstr(2),typs{12})),temp3(2)=0;else temp3(2)=1;end       if ((temp3(1)==1)&(temp3(2)==1))	%Do nothing       elseif ((temp3(1)==1)&(temp3(2)==0))	%Vectorize then let 0,0 take care of mxi if needed	temp1(1)=parens(1);temp1(2)=centercomma(1);	funstr{i}=[funstr{i}(1:temp1(1)),'[',funstr{i}(temp1(1)+1:temp1(2)-1),']',funstr{i}(temp1(2):end)];	count=1;gotto=i;       elseif ((temp3(1)==0)&(temp3(2)==1))	%Vectorize then let 0,0 take care of mxi if needed	temp1(1)=centercomma(1);temp1(2)=parens(2);	funstr{i}=[funstr{i}(1:temp1(1)),'[',funstr{i}(temp1(1)+1:temp1(2)-1),']',funstr{i}(temp1(2):end)];	count=1;gotto=i;       elseif ((temp3(1)==0)&(temp3(2)==0))	%Add mxi if needed	for k=1:howmany	 if count==0	  if strncmp(subscripts{k}(1),'[',1),goonimag=0;else;goonimag=1;end	  if length(find(subscripts{k}==':'))>0,goonimag=0;end%%%	  if length(subscripts{k})>3%%%	   if strcmp(subscripts{k}(1:4),'mxv(')%%%	    goonimag=0;%%%	   end%%%	  end	  if goonimag	   if k==1,temp1(1)=parens(1);temp1(2)=centercomma(1); end	   if k==2,temp1(1)=centercomma(1);temp1(2)=parens(2); end	   funstr{i}=[funstr{i}(1:temp1(1)),'[',funstr{i}(temp1(1)+1:temp1(2)-1),']',funstr{i}(temp1(2):end)];	   count=1;gotto=i;	  end	 end	end       end      end      if count==1       updatefunstr(i);      end     end    end    if count==1, break; end   end   if count==1, break; end  end end if want_kb,disp('finished with subscript vectorizing'),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 for, while, if, keywords groups%try fprintf(1,' ');pticker=pticker+1; if want_fb&(~want_kb),fprintf(1,' fixing if, for, etc keywords ...................... 1');end for i=1: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  switch funstrwords{i}{1}   case 'call'   case 'case'    funstr{i}=[funstr{i}(1:funstrwords_e{i}(1)+1),'(int(',convertconditional(funstr{i}(funstrwords_e{i}(1)+2:end-1)),'));'];   case 'else'   case 'elseif'    funstr{i}=['elseif (',convertconditional(funstr{i}(funstrwords_e{i}(1)+2:end-1)),') then;'];   case 'for'    temp=findend(i,s,funstr,funstrwords,keywords,keywordsbegin);    fid=find(funstr{i}=='=');fid=fid(fid>funstrwords_e{i}(1));fid=fid(1);    temp2=find(funstr{i}==':');    parens=[fid+1 length(funstr{i})-1];    tempstr=makeMATLABcallstring(length(temp2)+1,cell(1,length(temp2)+1),temp2,parens,i,j);%     for k=1:length(temp2)+1%      if k==1%       elseif%     end    temp3=cell(0);    temp3{1,1}=''; temp3{1,2}=''; temp3{1,3}=''; temp3{1,4}=''; temp3{1,5}=''; temp3{1,6}='';    temp3{2,1}=''; temp3{2,2}=''; temp3{2,3}=''; temp3{2,4}=''; temp3{2,5}=''; temp3{2,6}='';    if any(strcmp(tempstr(1),typs{2})), temp3{1,1}='nint(';temp3{1,2}=')'; end    if any(strcmp(tempstr(2),typs{2})), temp3{1,3}='nint(';temp3{1,4}=')'; end    if any(strcmp(tempstr(1),typs{1})), temp3{2,1}='mxs('; temp3{2,2}=')'; end    if any(strcmp(tempstr(2),typs{1})), temp3{2,3}='mxs('; temp3{2,4}=')'; end    if length(temp2)==1     funstr{i}=['do',funstr{i}(funstrwords_e{i}(1)+1:fid),temp3{1,1},temp3{2,1},funstr{i}(fid+1:temp2-1),temp3{1,2},temp3{2,2},',',temp3{1,3},temp3{2,3},funstr{i}(temp2+1:end-1),temp3{1,4},temp3{2,4},';'];    elseif length(find(funstr{i}==':'))==2    if any(strcmp(tempstr(3),typs{2})), temp3{1,5}='nint(';temp3{1,6}=')'; end    if any(strcmp(tempstr(3),typs{1})), temp3{2,5}='mxs('; temp3{2,6}=')'; end    funstr{i}=['do',funstr{i}(funstrwords_e{i}(1)+1:fid),temp3{1,1},temp3{2,1},funstr{i}(fid+1:temp2(1)-1),temp3{1,2},temp3{2,2},',',temp3{1,3},temp3{2,3},funstr{i}(temp2(2)+1:end-1),temp3{1,4},temp3{2,4},',',temp3{1,5},temp3{2,5},funstr{i}(temp2(1)+1:temp2(2)-1),temp3{1,6},temp3{2,6},';'];    end    funstr{temp}=['enddo',funstr{temp}(funstrwords_e{temp}(1)+1:length(funstr{temp}))];       case 'if'    funstr{i}=[funstr{i}(1:funstrwords_e{i}(1)+1),'(',convertconditional(funstr{i}(funstrwords_e{i}(1)+2:end-1)),') then;'];    temp=findend(i,s,funstr,funstrwords,keywords,keywordsbegin);    funstr{temp}=['endif',funstr{temp}(funstrwords_e{temp}(1)+1:length(funstr{temp}))];   case 'otherwise'    funstr{i}=['case default',funstr{i}(funstrwords_e{i}(1)+1:end)];   case 'switch'    funstr{i}=['select case (int(',convertconditional(funstr{i}(funstrwords_e{i}(1)+2:end-1)),'));'];    temp=findend(i,s,funstr,funstrwords,keywords,keywordsbegin);    funstr{temp}=['end select',funstr{temp}(funstrwords_e{temp}(1)+1:length(funstr{temp}))];       case 'while'    funstr{i}=['do while ',convertconditional(funstr{i}(funstrwords_e{i}(1)+2:end-1)),';'];    temp=findend(i,s,funstr,funstrwords,keywords);    funstr{temp}=['enddo',funstr{temp}(funstrwords_e{temp}(1)+1:length(funstr{temp}))];  end end updatefunstr; if want_kb,disp('finished fixing if, for, etc keywords.'),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 ((tempans=='n')|(tempans=='k')), keyboard, end, end%%%end%Change colon expressions%try fprintf(1,' ');pticker=pticker+1; if want_fb&(~want_kb),fprintf(1,' fixing colon expressons ........................... 1');end for i=1: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  temp=findstr(':',funstr{i});  if ~isempty(temp)   j=1;   while j<=length(temp)    if ((strcmp(funstrwords{i}{1},'disp'))|(strcmp(funstrwords{i}{1},'for')))     break    else%      if i>186%       funstr{i},kb%      end     temp1=temp(j);     [tempflag,howmany,subscripts,centercomma,parens]=inbracket(i,temp1,funstr);     if tempflag  % In a bracket      [temp2,howmany2,subscripts2,centercomma2,parens2]=inwhichlast(i,parens(1));      tempstr=makeMATLABcallstring(howmany,subscripts,centercomma,parens,i,j);      temp3={'','','';'','',''};      for k=1:howmany       if ~any(strcmp(tempstr(k),typs{7})) 	if length(find(strncmp('int',subscripts{k},3)))==0	 temp3{1,k}=[temp3{1,k},'int('];   temp3{2,k}=[temp3{2,k},')'];	end       end       if any(strcmp(tempstr(k),typs{1}))	if length(find(strncmp('mxs',subscripts{k},3)))==0	 temp3{1,k}=[temp3{1,k},'mxs('];   temp3{2,k}=[temp3{2,k},')'];        end       end      end      if howmany==3       if temp2==2 % bracketed expression is in subscript, 2 colons, switch order	fid={};	fid{1}=(~isspace(funstr{i}))&(find(funstr{i})>parens(2));	fid{2}=(~isspace(funstr{i}))&(find(funstr{i})<parens(1));	if (length(find(fid{1}(1)==[parens2 centercomma2]))>0) & (length(find(fid{2}(end)==[parens2 centercomma2]))>0) %Then we dont need (/ /) in fortran	 funstr{i}=[funstr{i}(1:parens(1)-1),temp3{1,1},subscripts{1},temp3{2,1},':',temp3{1,3},subscripts{3},temp3{2,3},':',temp3{1,2},subscripts{2},temp3{2,2},funstr{i}(parens(2)+1:end)];	else %we do	 funstr{i}=[funstr{i}(1:parens(1)-1),'[(iji,iji=',temp3{1,1},subscripts{1},temp3{2,1},',',temp3{1,3},subscripts{3},temp3{2,3},',',temp3{1,2},subscripts{2},temp3{2,2},')]',funstr{i}(parens(2)+1:end)];	end	j=j+howmany-1;       elseif temp2==1 % Bracketed expression nested in another bracket	funstr{i}=[funstr{i}(1:parens(1)-1),'[linspace((',subscripts{1},'),fix(((',subscripts{3},')-(',subscripts{1},'))/(',subscripts{2},'))*(',subscripts{2},')+(',subscripts{1},'),fix(((',subscripts{3},')-(',subscripts{1},'))/(',subscripts{2},'))+1)]',funstr{i}(parens(2)+1:end)];       else % Bracketed expression by itself or in another context, return array	funstr{i}=[funstr{i}(1:parens(1)-1),'linspace((',subscripts{1},'),fix(((',subscripts{3},')-(',subscripts{1},'))/(',subscripts{2},'))*(',subscripts{2},')+(',subscripts{1},'),fix(((',subscripts{3},')-(',subscripts{1},'))/(',subscripts{2},'))+1)',funstr{i}(parens(2)+1:end)];       end      elseif howmany==2 % bracketed expression, 1 colon, not in subscript. Must return array       if ~insubscript(i,temp(j))        funstr{i}=[funstr{i}(1:parens(1)-1),'spread(',subscripts{1},'+[(iji,iji=int(0),int(mxs(floor(dble(',subscripts{2},'-(',subscripts{1},'))))))],1,1)',funstr{i}(parens(2)+1:end)];       end       if temp2==2 % bracketed expression, 1 colon, in subscript. add int() if needed        fid={};	fid{1}=find((~isspace(funstr{i}))&(find(funstr{i})>parens(2)));	fid{2}=find((~isspace(funstr{i}))&(find(funstr{i})<parens(1)));	if (length(find(fid{1}(1)==[parens2 centercomma2]))>0) & (length(find(fid{2}(end)==[parens2 centercomma2]))>0) %Then we dont need (/ /) in fortran	 funstr{i}=[funstr{i}(1:parens(1)-1),temp3{1,1},subscripts{1},temp3{2,1},':',temp3{1,2},subscripts{2},temp3{2,2},funstr{i}(parens(2)+1:end)];	else %we do	 funstr{i}=[funstr{i}(1:parens(1)-1),'[(iji,iji=',temp3{1,1},subscripts{1},temp3{2,1},',',temp3{1,2},subscripts{2},temp3{2,2},')]',funstr{i}(parens(2)+1:end)];	end	j=j+howmany-1;       end      end      updatefunstr(i);     else % Not in a bracket      [tempflag,howmany,subscripts,centercomma,parens]=inwhichlast(i,temp1);      if tempflag==2 % But we are in a subscript last       temp2=[];	 temp3=[];       for k=1:howmany % Find which subscript (k) this colon expression is in, should be 2 subs	if k==1	 temp2(1)=parens(1); temp2(2)=centercomma(1);	elseif k==howmany	 temp2(1)=centercomma(end); temp2(2)=parens(2);	else	 temp2(1)=centercomma(k-1); temp2(2)=centercomma(k);	end	if ((temp1>temp2(1))&(temp1<temp2(2)))	 temp3=k;	 break	end       end       fid=find(((temp>temp2(1))&(temp<temp2(2))));       tempstr='';       howmany=length(fid)+1;       %here next, there has to be a better way       for k=1:howmany	if k==1	 temp3(1)=temp2(1); temp3(2)=temp(fid(1));	elseif k==length(fid)+1	 temp3(1)=temp(fid(end)); temp3(2)=temp2(2);	else	 temp3(1)=temp(fid(k-1)); temp3(2)=temp(fid(k));	end	tempstr=[tempstr,makeMATLABcallstring(1,{funstr{i}(temp3(1)+1:temp3(2)-1)},[],[temp3(1)+1 temp3(2)-1],i,inf)];	subscripts{k}=funstr{i}(temp3(1)+1:temp3(2)-1);       end       temp3={'','','';'','',''};       for k=1:howmany	if ~any(strcmp(tempstr(k),typs{7}))	 if length(find(strncmp('int',subscripts{k},3)))==0	  temp3{1,k}=[temp3{1,k},'int('];   temp3{2,k}=[temp3{2,k},')'];	 end	end	if ~any(strcmp(tempstr(k),typs{5}))	 if length(find(strncmp('mxs',subscripts{k},3)))==0	  temp3{1,k}=[temp3{1,k},'mxs('];   temp3{2,k}=[temp3{2,k},')'];         end	end       end       if howmany==3 % colon expression is in subscript, 2 colons, switch order	funstr{i}=[funstr{i}(1:temp2(1)),temp3{1,1},subscripts{1},temp3{2,1},':',temp3{1,3},subscripts{3},temp3{2,3},':',temp3{1,2},subscripts{2},temp3{2,2},funstr{i}(temp2(2):end)];	j=j+howmany-1;       elseif howmany==2 % colon expression is in subscript, 1 colon	funstr{i}=[funstr{i}(1:temp2(1)),temp3{1,1},subscripts{1},temp3{2,1},':',temp3{1,2},subscripts{2},temp3{2,2},funstr{i}(temp2(2):end)];	j=j+howmany-1;       end       updatefunstr(i);      else       if ~strcmp(funstrwords{i}{1},'for')	disp(['Encountered a colon expression not enclosed in brackets outside ',r,'a subscript. Put brackets around this colon expression. *error*',r,'          ',funstr{i}]);keyboard       else	j=inf;       end      end     end    end    temp=findstr(':',funstr{i});   end  end end if want_kb,disp('finished fixing colon expressions'),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 calls to matlab function with no fortran equivalent (user m-files).%try fprintf(1,' ');pticker=pticker+1; if want_fb&(~want_kb),fprintf(1,' performing word conversion ........................ 1');end count=1;gotto=1;maxmxinputs={'r'};maxmxinputs0={'r'};multinum=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    goon='';goonimag='';fid='';    for j=length(funstrwords{i}):-1:1

⌨️ 快捷键说明

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