## 20-5 ?‰ç”¨ç¯„ä?ä¸‰ï?MATLAB ç¨‹å?ç¢¼å?äº?

¦b§Ú­Ì¹êÅç«Ç¶i¦æ¬ã¨sªº¹Lµ{¤¤¡A¨C­Ó¤H³£·|¶}µo¬ÛÃöªº MATLAB µ{¦¡¡A¨Ã·J¾ã¦¨¤@­Ó­Ó¤u¨ã½c¡]Toolbox¡^¡A¥H«K¥L¤H¨Ï¥Î¡C¦ý¬O¦bµo®iªº¹Lµ{¤¤¡Aµ{¦¡½X±±»Ý­n­×§ï¡A¬°¤F¤è«KºÞ²z¡A§Ú­Ì§â¬ÛÃöªº»¡©ú¤]©ñ¦bµ{¦¡½X¤º¡A¦p¦ó¯à¤@¥Ø¤FµM¦a¬Ý¨ì³o¨Ç»¡©ú¡A¬O¤@¥ó«Ü­«­nªº¤u§@¡C

Example¡]fileAccess/utility/index.asp¡^¡G

<%@language=JScript%>
<% title="Utility Toolbox: MATLAB µ{¦¡»¡©ú" %>
<%
function getMFileUsage(fileName){
fso = new ActiveXObject("Scripting.FileSystemObject");
fid=fso.OpenTextFile(fileName, 1);
fid.Close();
lines=contents.split("\n");
output=new Object();

// ====== Check if a function
pattern=/^\s*function\s/i;
line=lines[0];
output.isFunction=false;
if (line.match(pattern) != null)
output.isFunction=true;

// ====== Get H1 help
pattern=/^%\s*(.*)/i;
output.h1="";
for (i=0; i<lines.length; i++)
if (lines[i].match(pattern) != null){
output.h1=RegExp.$1; break; } // ====== Usage line pattern=/^%\s*Usage:\s*(.*)/i; output.usage=""; startLine=-1; for (i=0; i<lines.length; i++) if (lines[i].match(pattern) != null){ output.usage=RegExp.$1;
startLine=i;
break;
}

// ====== Argument documentation
pattern=/^%\s*(.*)/i;
output.argumentDoc="";
if (startLine>=0)
for (i=startLine+1; i<lines.length; i++)
if ((lines[i].match(pattern) != null) && (RegExp.$1 != "")) output.argumentDoc = output.argumentDoc + "\\n" + RegExp.$1;
else
break;

// ====== Return the final output
return(output);
}
%>

<html>
<title><%=title%></title>
<meta HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=big5">
<meta HTTP-EQUIV="Expires" CONTENT="0">
<style>
td {font-family: "¼Ð·¢Åé", "helvetica,arial", "Tahoma"}
A:hover {text-decoration: underline}
</style>

<body background="/jang/graphics/background/yellow.gif">
<font face="¼Ð·¢Åé">
<h2 align=center><%=title%></h2>
<h3 align=center><a target=_blank href="/jang">±i´¼¬P</a></h3>
<hr>

<blockquote>¥»¤u¨ã½c´£¨Ñ MATLAB ±¥Îªº¤½¥Î¨ç¼Æ¡A¤]Åwªï¤j®a°^Äm¡C</blockquote>

<%
fso = new ActiveXObject("Scripting.FileSystemObject");
fullPath = Server.MapPath(".");

webPath=Request.ServerVariables("PATH_INFO");
realPath=Request.ServerVariables("PATH_TRANSLATED");
rarWebPath=fso.GetParentFolderName(webPath)+".rar";
rarRealPath=fso.GetParentFolderName(realPath)+".rar";
rarFile=fso.GetFileName(fso.GetParentFolderName(realPath))+".rar";
if (fso.FileExists(rarRealPath)){
%>
<h3><img src="/jang/graphics/dots/redball.gif">¾ã­Ó¥Ø¿ýÀ£ÁYÀÉ¡G<a href="<%=rarWebPath%>"><%=rarFile%></a></h3>
<%}%>

<h3><img src="/jang/graphics/dots/redball.gif">»Ý­n¦@¥Îªº¤u¨ã½c</h3>
<blockquote>µL¡C</blockquote>

<!== ¦C¥X¨ç¼Æ -->
<h3><img src="/jang/graphics/dots/redball.gif">¨ç¼Æ¦Cªí</h3>
<table border=1 align=center>
<tr>
<%
fd = fso.GetFolder(fullPath);
fc = new Enumerator(fd.Files);
for (; !fc.atEnd(); fc.moveNext()){
fileName=fc.item()+"";
ext=fso.GetExtensionName(fileName);
if ((ext=="m") || (ext=="M")){
f = fso.GetFile(fileName);
out=getMFileUsage(fileName);
if (out.isFunction){
Response.write("\n<tr>\n");
Response.write("<td><a target=_blank href=\"" + f.Name + "\">" + f.Name + "</a></td>");
Response.write("<td>" + out.h1 + "&nbsp;</td>");
doc=out.argumentDoc;
doc=doc.replace(/"/g, "\\\"");		// ±N¦r¦ê­ì¦³ªº " ¥N´«¦¨ \"
doc=doc.replace(/'/g, "\\\'");		// ±N¦r¦ê­ì¦³ªº ' ¥N´«¦¨ \'
if (doc!="")
Response.write("<td><a href='javascript:alert(\"" + doc + "\")'>" + out.usage + "</a>&nbsp;</td>");
else
Response.write("<td>" + out.usage + "</td>");
Response.write("<td align=right>" + f.Size + "</td>");
}
}
}
%>
</table>

<table border=1 align=center>
<tr>
<%
fd = fso.GetFolder(fullPath);
fc = new Enumerator(fd.Files);
for (; !fc.atEnd(); fc.moveNext()){
fileName=fc.item()+"";
items=fileName.split(".");
ext=items[items.length-1];
if ((ext=="m") || (ext=="M")){
f = fso.GetFile(fileName);
out=getMFileUsage(fileName);
if (!out.isFunction){
Response.write("\n<tr>\n");
Response.write("<td><a href=\"" + f.Name + "\">" + f.Name + "</a></td>");
Response.write("<td>" + out.h1 + "&nbsp;</td>");
Response.write("<td align=right>" + f.Size + "</td>");
}
}
}
%>
</table>

<!== ¦C¥X¨ä¥LÀÉ®× -->
<h3><img src="/jang/graphics/dots/redball.gif">¨ä¥LÀÉ®×</h3>
<table border=1 align=center>
<tr>
<th>ÀÉ®×¦WºÙ<th>ÀÉ®×¤j¤p
<%
fd = fso.GetFolder(fullPath);
fc = new Enumerator(fd.Files);
for (; !fc.atEnd(); fc.moveNext()){
fileName=fc.item()+"";
items=fileName.split(".");
ext=items[items.length-1];
if ((ext!="m") && (ext!="M")){
f = fso.GetFile(fileName);
Response.write("\n<tr>\n");
Response.write("<td><a href=\"" + f.Name + "\">" + f.Name + "</a></td>");
Response.write("<td align=right>" + f.Size + "</td>");
}
}
%>
</table>

<ul>
<li>½Ð±N¥»¥Ø¿ýªº index.asp ©ñ¸m¨ì§Aªº toolbox ¥Ø¿ý¡A¦P®É¦b IIS ªº¡u¥Ø¿ý¹w³]¤å¥ó¡v¥[¤J index.asp¡A¦¹®É·í§O¤H¸g¥ÑÂsÄý¾¹³s±µ¨ì§Aªº toolbox ¥Ø¿ý¡A¦¹ index.asp §Y·|¦Û°Ê§ì¥X¦U­Ó MATLAB µ{¦¡½Xªº¬ÛÃö»¡©ú¡A¨Ã¥ß¨èÅã¥Ü¦bºô­¶¤W¡C
<ul>
<li>­Y¬O¨ç¼Æ¡A²Ä¤@¦Cªº²Ä¤@­Ó­^¤å¦r¥²¶·¬O¡ufunction¡v¡C
</ul>
<li>¬°¨Ï¨ç¼Æ«K©ó¥L¤H­«½Æ¨Ï¥Î¡A½Ð¦b¼¶¼g¨ç¼Æ®É¡Aª·N¤U¦C¨Æ¶µ¡G
<ul>
</ul>
<li>¦pªG toolbox ¸ô®|¬O /jang/toolbox/utility ®É¡Aindex.asp ·|¦Û°Ê¥h§ä /jang/toolbox/utility.asp ¨Ã±N¤§µø¬°¾ã­Ó toolbox ªºÀ£ÁYÀÉ¡C¡]¦]¦¹¦pªG§A¦³§ó·s toolbox¡A°O±o­n­«·sÀ£¤@¥÷ .rar ÀÉ®×¡A¨Ã©ñ¦b¦P¤@¼h¥Ø¿ý¡C¡^
</ul>

<hr>

<script language="JavaScript">
document.write("Last updated on " + document.lastModified + ".")
</script>

<a href="/jang/sandbox/asp/lib/editfile.asp?FileName=<%=Request.ServerVariables("PATH_INFO")%>"><img align=right border=0 src="/jang/graphics/invisible.gif"></a>
</font>
</body>
</html>