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

📄 mat2html

📁 著名的seismiclab的代码 是地震学研究人员必备的工具
💻
📖 第 1 页 / 共 2 页
字号:
  print "Reading $file\n" if $verbose;  while (<MFILE>) {    chop;    # If it's the function declaration line, then store it and skip    if (/^\s*function/) {      s/^\s*function\s*//;      $synopsis{$file} = $_;      $mtype{$file} = "function";      next;    }    # Compress multiple %'s to a single %    s/%+/%/g;    # Process comment lines and code lines separately    if (/^\s*%/) {      # cut out comment marker and surrounding white space      s/^\s*%\s*//;      # Store first comment line in lookfor      if (!$lookfor{$file}) {        $lookfor{$file} = $_;      }      # Canonicalize to lower case, split on nonalphanumerics,      # and count things that look like matlab identifiers.      tr/A-Z/a-z/;      grep($hsymbols{$_}++,grep(/[a-z]\w*/,split('\W',$_)))    } else {      # Split off and ignore trailing comments      # Split on nonalphanumerics and count identifiers      ($statement,$comment) = split('%',$_,2);      grep($csymbols{$_}++,grep(/[a-zA-Z]\w*/,split('\W',$statement)));    }  }  close MFILE;  # Now mark each name that appears in the list of symbols  # Compute the names appearing among the symbols in the code section  # (@csym), in the help section (@hsym)  if ($opt_g) {    # If global, search among all symbols    @csym = grep($csymbols{$_},@names);    @hsym = grep($hsymbols{$_},@names);  } else {    # If not global, search among files appearing in the same directory    $dir = $mdir{$file};    @csym = grep(($csymbols{$_} && ($dir eq $mdir{$mfile{$_}})), @names);    @hsym = grep(($hsymbols{$_} && ($dir eq $mdir{$mfile{$_}})), @names);  }  # Now record the cross references in $cref and $href  grep($cref{$file,$mfile{$_}}=$csymbols{$_},@csym);  grep($href{$file,$mfile{$_}}=$hsymbols{$_},@hsym);  undef(%csymbols);  undef(%hsymbols);}########################################################################  Setup the html directories######################################################################## Create an html subdirectory name for every unique matlab directory in the# list @mdirs. The name is constructed using the tail of the directory# prefaced by a unique number.##  $hdir{$mdir}   - html subdirectory for matlab directory $mdir$x = 1;foreach (@mdirs) {  @z = reverse(split("/",$_));  $hdir{$_} = "$x.".@z[0];  $x++;}# for each .m file, name a corresponding .html fileforeach (@mfiles) {  $hfile{$file} = $name{$_}.".html";}# Now test a build the corresponding html directories.print "Checking HTML directories.\n" if $verbose;if (!-e $hroot) {  mkdir($hroot,umask) || die("Cannot create directory $hroot\n");  chmod 0755, $hroot;}opendir(HDIR,$hroot) || die ("Cannot open directory $hroot\n");closedir(HDIR);die("HTML directory $hroot is not writable\n") if !-w $hroot;print "HTML Directory $hroot is OK\n" if $verbose;foreach (@mdirs) {  local($x) = $hroot."/".$hdir{$_};  if (!-e $x) {    mkdir($x,umask) || die("Cannot create directory $x\n");    chmod(0755,$x);  }  opendir(HDIR,$x) || die ("Cannot open directory $x\n");  closedir(HDIR);  die("HTML directory $x is not writable\n") if !-w $x;  print "HTML Directory $x is OK\n" if $verbose;}########################################################################  If verbose mode, write a sparse matrix with the xref data######################################################################## For kicks, let's write out name and cross reference info in a# sparse matrix format. These can be anaylzed using matlab.if ($verbose) {  local($x,$y,$i,$j);  open(TXT,">$hroot/names.txt");  foreach (@mfiles) {    $b = " " x (20-length($name{$_}));    print TXT $name{$_},$b,$_,"\n";  }  close TXT;  open(DAT,">$hroot/xref.dat");  $i = 0;  foreach $x (@mfiles) {    $j = 0;    $i++;    foreach $y (@mfiles) {      $j++;      print DAT "$i  $j  $cref{$x,$y}\n" if $cref{$x,$y};    }  }  close(DAT);}########################################################################  Write the master index file#######################################################################$indexfile = "$hroot/index.html";print "Writing master $indexfile\n" if $verbose;open(HFILE,">$indexfile") || die("Cannot open index file $indexfile\n");print HFILE "<TITLE>Matlab Index</TITLE>\n";print HFILE "<BODY>\n";print HFILE "<H1>Matlab Index</H1>\n";&tagline;# Print a short introduction# Print directory listingprint HFILE "<HR><H2>Matlab Directory Indices</H2>\n<pre>\n";print HFILE "<UL>\n";foreach $dir (@mdirs) {  print HFILE "<LI>",&anchor_url("$hdir{$dir}/index.html",$dir),"</LI>\n";}print HFILE "</UL>\n";# Include links to every file that was foundprint HFILE "<HR><H2>Identifiers found in these directories</H2>\n";# We'll do this five across in alphabetical order$i = 1;foreach (@names) {  $b = " " x (15 - length($_));  $html = "$hdir{$mdir{$mfile{$_}}}/$_.html";  print HFILE &anchor_url($html,$_),$b;  print HFILE "\n" if (0 == $i%5);  $i++;}print HFILE "<HR></BODY>\n";close(HFILE);########################################################################  Write an index for each html subdirectory#######################################################################@readme = grep(/readme/i,@mfiles);foreach $dir (@mdirs) {  $indexfile = "$hroot/$hdir{$dir}/index.html";  print "Writing an index file $indexfile\n" if $verbose;  open(HFILE,">$indexfile") || die("Cannot open index file $indexfile\n");  print HFILE "<TITLE>Index for Directory $dir</TITLE>\n";  print HFILE "<BODY>\n";  print HFILE &anchor_url("../index.html","[Master Index]"),"\n";  print HFILE "<H1>Index for $dir</H1>\n";  &tagline;  # Now look for a Readme.m file, seemingly a Matlab standard. If there  # is one, then the help portion is included in the index file.  foreach $file (@readme) {    next if !($mdir{$file} eq $dir);    open(MFILE,$file) || die("Cannot open the file $file");    # Help Cross Reference information    undef(@zref);    foreach (@mfiles) {      push(@zref,$name{$_}) if $href{$file,$_};    }    # Look for the matlab help text block    $headline = "Readme";    &writehelpblock;  }  # Now write the index catalog for the .m files in this directory  print HFILE "<HR><H2>Matlab files in this Directory</H2>\n<pre>\n";  foreach $file (grep($dir eq $mdir{$_},@mfiles)) {    $b = " " x (15 - length($name{$file}));    $html = $name{$file}.".html";    print HFILE &anchor_url($html,$name{$file}),"$b$lookfor{$file}\n";  }  print HFILE "</pre>\n";  print HFILE "<HR></BODY>\n";  close(HFILE);}########################################################################  Write an html file for every m-file######################################################################## Now write the html file for each matlab file. Need to reread each matlab# file to find the help text. Note that we can't do this in a single loop# because we want the back reference information, and also some people# put the help text before the function declarations.  # Need a list of mfiles with unique identifiers@umfiles = values(%mfile);foreach $file (@mfiles) {  $h = "$hroot/$hdir{$mdir{$file}}/$name{$file}.html";    print "Writing $h\n" if $verbose;  # Cross Reference information  # Find list of names.  undef(@xref);  undef(@yref);  undef(@zref);  foreach (@umfiles) {    next if ($name{$_} eq $name{$file});      push(@xref,$name{$_}) if $cref{$file,$_}; # files we call      push(@yref,$name{$_}) if $cref{$_,$file}; # files that call us      push(@zref,$name{$_}) if $href{$file,$_}; # comment lines    }  open(MFILE,"<$file") || die("Cannot open $file");  open(HFILE,">$h") || die("Cannot open $h");  print HFILE "<TITLE>$hdir{$file}/$hfile{$file}</TITLE>\n";  print HFILE "<BODY>\n";  print HFILE &anchor_url("../index.html","[Master Index]"),"\n";  print HFILE &anchor_url("index.html","[Index for $mdir{$file}]"),"\n";  print HFILE "<H1>$name{$file}</H1>\n";  print HFILE "<H2>($mdir{$file}/$name{$file}.m)</H2>\n";  # If this is a function, then write out the first line as a synposis  if ($mtype{$file}) {    print HFILE "<HR><H3>Function Synopsis</H3>\n";    print HFILE "<pre>$synopsis{$file}</pre>\n";  }  # Write the help block  $headline = "Help text";  &writehelpblock;  print HFILE "<HR><H3>Cross-Reference Information</H3>" if (@xref || @yref);  if (@xref) {    print HFILE "This $mtype{$file} calls\n";    print HFILE "<pre><UL>\n";    foreach (sort @xref) {      $html = "../$hdir{$mdir{$mfile{$_}}}/$_.html";      $b = " " x (15 - length($_));      print HFILE "<LI>",&anchor_url($html,$_),"$b$mfile{$_}</LI>\n";    }    print HFILE "</UL></pre>\n";  }  if (@yref) {    print HFILE "This $mtype{$file} is called by\n";    print HFILE "<pre><UL>\n";    foreach (sort @yref) {      $html = "../$hdir{$mdir{$mfile{$_}}}/$_.html";      $b = " " x (15 - length($_));      print HFILE "<LI>",&anchor_url($html,$_),"$b$mfile{$_}</LI>\n";    }    print HFILE "</UL></pre>\n";  }  # Include source text if requested  if ($opt_i) {    print HFILE "<HR><H3>Listing of $mtype{$file} $file</H3>\n";    seek(MFILE,0,0);    print HFILE "<pre>\n";    while (<MFILE>) {      &htmlchar;      if (/^\s*%/) {        foreach $z (@zref) {          next if /<A.*$z.*A>/;          $html = "../$hdir{$mdir{$mfile{$z}}}/$z.html";          s/(\W+)($z)(\W+)/$1.&anchor_url($html,$2).$3/egi;        }      } else {        foreach $x (@xref) {          next if /<A.*$x.*A>/;          $html = "../$hdir{$mdir{$mfile{$x}}}/$x.html";          s/(\W+)($x)(\W+)/$1.&anchor_url($html,$2).$3/eg;          s/^(\s*)($x)(\W+)/$1.&anchor_url($html,$2).$3/eg;        }      }      print HFILE $_;    }    print HFILE "</pre>\n";  }    # Print a date stamp  print HFILE "<HR>\n";  &tagline;  print HFILE "</BODY>";  close(MFILE);  close(HFILE);}########################################################################  Do some final statistics#######################################################################print $anchor_count," HTML anchors were written.\n" if $verbose;print $page_count," HTML files were written.\n" if $verbose;

⌨️ 快捷键说明

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