KerMor  0.9
Model order reduction for nonlinear dynamical systems and nonlinear approximation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
MatlabDocMaker.m
Go to the documentation of this file.
1 
2 
3 /* (Autoinserted by mtoc++)
4  * This source code has been filtered by the mtoc++ executable,
5  * which generates code that can be processed by the doxygen documentation tool.
6  *
7  * On the other hand, it can neither be interpreted by MATLAB, nor can it be compiled with a C++ compiler.
8  * Except for the comments, the function bodies of your M-file functions are untouched.
9  * Consequently, the FILTER_SOURCE_FILES doxygen switch (default in our Doxyfile.template) will produce
10  * attached source files that are highly readable by humans.
11  *
12  * Additionally, links in the doxygen generated documentation to the source code of functions and class members refer to
13  * the correct locations in the source code browser.
14  * However, the line numbers most likely do not correspond to the line numbers in the original MATLAB source files.
15  */
16 
17 class MatlabDocMaker {
128  public: /* ( Constant ) */
129 
130  static const .char DOXYFILE_TEMPLATE = "Doxyfile.template";
142  static const .char LATEXEXTRAS_TEMPLATE = "latexextras.template";
155  static const .char MTOCPP_CONFIGFILE = "mtocpp.conf";
168  public: /* ( Static ) */ /* ( Constant ) */
169 
170  static function charname = getProjectName() {
171 
172  name = " KerMor ";
173  }
187  /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
188  *% End of user defined part.
189  *%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% */
190 
191  public: /* ( Static, Sealed ) */ /* ( Constant ) */
192 
193  static function chardir = getOutputDirectory() {
194  dir = MatlabDocMaker.getPref(" outdir ");
195  }
208  static function chardir = getSourceDirectory() {
209  dir = MatlabDocMaker.getPref(" srcdir ");
210  }
223  static function chardir = getConfigDirectory() {
224  dir = MatlabDocMaker.getPref(" confdir ");
225  }
242  static function chardesc = getProjectDescription() {
243  desc = MatlabDocMaker.getPref(" proj_desc ", );
244  }
258  static function setProjectDescription(char value) {
259  if ~ischar(value)
260  error(" The description must be a char array. ");
261  end
262  MatlabDocMaker.setPref(" proj_desc ", value);
263  }
277  static function charversion = getProjectVersion() {
278  version = MatlabDocMaker.getPref(" proj_ver ", " 0 ");
279  }
296  static function setProjectVersion(char value) {
297  if ~ischar(value)
298  error(" The project version must be a char array. ");
299  end
300  MatlabDocMaker.setPref(" proj_ver ", value);
301  }
315  static function fullPath = getProjectLogo() {
316  logoFile = MatlabDocMaker.getPref(" proj_logo ",);
317  fullPath = ;
318  if ~isempty(logoFile)
319  if isempty(fileparts(logoFile))
320  fullPath = fullfile(MatlabDocMaker.getConfigDirectory,logoFile);
321  else
322  fullPath = logoFile;
323  end
324  if exist(fullPath," file ") ~= 2
325  warning(" MatlabDocMaker:getLogo ",[" Could not find logo file '%s'.\n "...
326  " No logo will be shown in documentation output. "],logoFile);
327  end
328  end
329  }
345  static function setProjectLogo(char value) {
346  if nargin < 1
347  [f, p] = uigetfile(" *.* ", " Select project logo ", pwd);
348  if f ~= 0
349  value = fullfile(p,f);
350  else
351  fprintf(2," No file selected. Aborting.\n ");
352  return;
353  end
354  end
355  if ~ischar(value)
356  error(" The project logo file must be a char array. ");
357  end
358  if ~isempty(value)
359  fullPath = value;
360  if isempty(fileparts(value))
361  fullPath = fullfile(MatlabDocMaker.getConfigDirectory, value);
362  end
363  if ~exist(fullPath," file ")
364  error(" Invalid logo file: Could not find '%s' ",fullPath);
365  end
366  end
367  MatlabDocMaker.setPref(" proj_logo ", value);
368  }
386  public: /* ( Static ) */ /* ( Constant ) */
387 
388 
389  static function open() {
390  index = fullfile(MatlabDocMaker.getOutputDirectory, " index.html ");
391  if ispc
392  winopen(index);
393  else
394  [s, m] = system(sprintf(" xdg-open '%s' ",index));
395  if s ~= 0
396  fprintf(2," Could not find/execute xdg-open: %s ",m);
397  web(index);
398  end
399  end
400  }
410  static function create(varargin) {
411 
412  /* % Preparations */
413 
414  ip.addParamValue('open',false,@islogical);
415  ip.addParamValue('latex',false,@islogical);
416  ip.parse(varargin[:]);
417  genlatex = ip.Results.latex;
418 
419  /* Check for correct setup */
420  cdir = MatlabDocMaker.getConfigDirectory;
421  srcdir = MatlabDocMaker.getSourceDirectory;
422  outdir = MatlabDocMaker.getOutputDirectory;
423  /* Check if doxygen config file template exists */
424  doxyfile_in = fullfile(cdir,MatlabDocMaker.DOXYFILE_TEMPLATE);
425  if exist(doxyfile_in," file ") ~= 2
426  error(" No doxygen configuration file template found at '%s' ",doxyfile_in);
427  end
428 
429  lstr = ;
430  if genlatex
431  lstr = " (+Latex) ";
432  end
433  fprintf([" Starting creation of doxygen/mtoc++ powered HTML%s documentation for '%s' (%s)\n "...
434  " Sources: %s\nOutput to: <a href='matlab:MatlabDocMaker.open'>%s</a>\nCreating config files... "],lstr,...
435  MatlabDocMaker.getProjectName,MatlabDocMaker.getProjectVersion,...
436  srcdir,outdir);
437 
438  /* Operation-system dependent strings */
439  strs = struct;
440  if isunix
441  strs.null= " /dev/null ";
442  strs.silencer= ;
443  elseif ispc
444  strs.null= " NUL ";
445  strs.silencer= " @ "; /* argh that took a while to remember.. */
446 
447  else
448  error(" Current platform not supported. ");
449  end
450 
451  /* Save current working dir and change into the KerMor home
452  * directory; only from there all classes and packages are
453  * detected properly. */
454  curdir = pwd;
455  cd(srcdir);
456 
457  /* Append the configuration file directory to the current PATH */
458  pathadd = [pathsep cdir];
459  setenv(" PATH ",[getenv(" PATH ") pathadd]);
460 
461  mtoc_conf = fullfile(cdir,MatlabDocMaker.MTOCPP_CONFIGFILE);
462  filter = sprintf(" %smtocpp ",strs.silencer);
463  if exist(mtoc_conf," file ")
464  if isunix
465  strs.filter= " mtocpp_filter.sh ";
466  strs.farg= " $1 ";
467  elseif ispc
468  strs.filter= " mtocpp_filter.bat ";
469  strs.farg= " %1 ";
470  else
471  error(" Current platform not supported. ");
472  end
473  /* % Creation part */
474  cdir = MatlabDocMaker.getConfigDirectory;
475  /* Create "configured" filter script for inclusion in doxygen */
476  filter = fullfile(cdir,strs.filter);
477  f = fopen(filter," w ");
478  fprintf(f," %smtocpp %s %s ",strs.silencer,strs.farg,mtoc_conf);
479  fclose(f);
480  if isunix
481  unix([" chmod +x " filter]);
482  end
483  end
484 
485  /* % Prepare placeholders in the Doxyfile template */
486  cdirfwd = strrep(cdir," \ "," / ");
487  m = [" _OutputDir_ " strrep(outdir," \ "," \\ "); ...
488  " _SourceDir_ " strrep(MatlabDocMaker.getSourceDirectory," \ "," \\ ");...
489  " _ConfDir_ " strrep(cdir," \ "," \\ ");...
490  " _ConfDirFwdSlash_ " cdirfwd;...
491  " _ProjectName_ " MatlabDocMaker.getProjectName; ...
492  " _ProjectDescription_ " MatlabDocMaker.getProjectDescription; ...
493  " _ProjectLogo_ " strrep(MatlabDocMaker.getProjectLogo," \ "," \\ "); ...
494  " _ProjectVersion_ " MatlabDocMaker.getProjectVersion; ...
495  " _MTOCFILTER_ " strrep(filter," \ "," \\ "); ...
496  " _FileSep_ " filesep
497  ];
498 
499  /* Check for latex extra stuff */
500  texin = fullfile(cdir,MatlabDocMaker.LATEXEXTRAS_TEMPLATE);
501  latexextras = ;
502  if exist(texin," file ") == 2
503  latexstr = strrep(fileread(texin)," _ConfDir_ ",cdir);
504  latexstr = strrep(latexstr," _ConfDirFwdSlash_ ",cdirfwd);
505  latexextras = fullfile(cdir," latexextras.sty ");
506  fid = fopen(latexextras," w+ "); fprintf(fid," %s ",latexstr); fclose(fid);
507  end
508  /* Always use "/" for latex usepackage commands, so replace "\" (effectively windows
509  * only) by "/", and dont pass the extension ".sty" as latex automatically adds it. */
510  m(end+1,:) = [" _LatexExtras_ " strrep(latexextras(1:end-4)," \ "," / ")];
511  L = " NO ";
512  if genlatex
513  L = " YES ";
514  end
515  m(end+1,:) = [" _GenLatex_ ",L];
516 
517  /* Check how to set the HAVE_DOT flag */
518  [s, ~] = system(" dot -V ");
519  if s == 0
520  HD = " YES ";
521  else
522  HD = " NO ";
523  fprintf(" no 'dot' found... ");
524  end
525  m(end+1,:) = [" _HaveDot_ ",HD];
526 
527  /* Read, replace & write doxygen config file */
528  doxyfile = fullfile(cdir," Doxyfile ");
529  doxyconfstr = regexprep(fileread(doxyfile_in),m(:,1),m(:,2));
530  fid = fopen(doxyfile," w "); fprintf(fid," %s ",doxyconfstr); fclose(fid);
531 
532  /* Fix for unix systems where the MatLab installation uses older
533  * GLIBSTD libraries than doxygen/mtoc++ */
534  ldpath = ;
535  if isunix
536  ldpath = " LD_LIBRARY_PATH= ";
537  end
538  /* Call doxygen */
539  fprintf(" running doxygen with mtoc++ filter... ");
540  [~,warn] = system(sprintf(" %sdoxygen '%s' 1>%s ",ldpath, doxyfile, strs.null));
541 
542  /* Postprocess */
543  fprintf(" running mtoc++ postprocessor... ");
544  [~,postwarn] = system(sprintf(" %smtocpp_post '%s' 1>%s ",ldpath,...
545  outdir, strs.null));
546  if ~isempty(postwarn)
547  warn = [warn sprintf(" mtoc++ postprocessor messages:\n ") postwarn];
548  end
549 
550  /* Create latex document if desired */
551  if genlatex
552  oldd = pwd;
553  latexerr = false;
554  latexdir = fullfile(outdir," latex ");
555  if exist(latexdir," dir ") == 7
556  if exist(fullfile(latexdir," refman.tex ")," file ") == 2
557  fprintf(" compiling LaTeX output... ");
558  cd(latexdir);
559  [s, latexmsg] = system(" make ");
560  if s ~= 0
561  warn = [warn sprintf(" LaTeX compiler output:\n ") latexmsg];
562  latexerr = true;
563  end
564  else
565  fprintf(" cannot compile LaTeX output: no refman.tex found... ");
566  end
567  end
568  cd(oldd);
569  end
570 
571  /* Tidy up */
572  fprintf(" cleaning up... ");
573  if isfield(strs," filter ")
574  delete(filter);
575  end
576  if ~isempty(latexextras)
577  delete(latexextras);
578  end
579  delete(doxyfile);
580 
581  /* % Post generation phase */
582  cd(curdir);
583  /* Restore PATH to previous value */
584  curpath = getenv(" PATH ");
585  setenv(" PATH ",curpath(1:end-length(pathadd)));
586  fprintf(" done!\n ");
587 
588  /* Process warnings */
589  showchars = 800;
590  warn = strtrim(warn);
591  if ~isempty(warn)
592  dispwarn = [warn(1:min(showchars,length(warn))) " [...] "];
593  fprintf(" First %d characters of warnings generated during documentation creation:\n%s\n ",showchars,dispwarn);
594  /* Write to log file */
595  log = fullfile(outdir," warnings.log ");
596  f = fopen(log," w "); fprintf(f," %s ",warn); fclose(f);
597  fprintf(2," MatlabDocMaker finished with warnings!\n ");
598  fprintf(" Complete log file at <a href='matlab:edit( "" %s "" )'>%s</a>.\n ",log,log);
599  /* Check for latex log file */
600  log = fullfile(outdir," _formulas.log ");
601  if exist(log," file ")
602  fprintf(" Found LaTeX formula log file. Check <a href='matlab:edit( "" %s "" )'>%s</a> for any errors.\n ",log,log);
603  end
604  /* Check for errors on latex generation */
605  if genlatex && latexerr
606  log = fullfile(latexdir," refman.log ");
607  fprintf(" There have been errors with LaTeX compilation. See log file at <a href='matlab:edit( "" %s "" )'>%s</a>.\n ",log,log);
608  end
609  else
610  fprintf(" MatlabDocMaker finished with no warnings!\n ");
611  end
612 
613  /* Open index.html if wanted */
614  if ip.Results.open
615  MatlabDocMaker.open;
616  end
617  }
633  static function setup() {
634 
635  /* % Validity checks */
636  fprintf(" <<<< Welcome to the MatlabDocMaker setup for your project '%s'! >>>>\n ",MatlabDocMaker.getProjectName);
637 
638  /* % Setup directories
639  * Source directory */
640  srcdir = MatlabDocMaker.getPref(" srcdir ",);
641  word = " keep ";
642  if isstruct(srcdir) || isempty(srcdir) || exist(srcdir," dir ") ~= 7
643  srcdir = pwd;
644  word = " set ";
645  end
646  str = sprintf(" Do you want to %s %s as your projects source directory?\n(Y)es/(N)o?: ",word,strrep(srcdir," \ "," \\ "));
647  ds = lower(input(str," s "));
648  if isequal(ds," n ")
649  d = uigetdir(srcdir," Please select the projects source directory ");
650  if d == 0
651  error(" No source directory specified. Aborting setup. ");
652  end
653  srcdir = d;
654  end
655  MatlabDocMaker.setPref(" srcdir ",srcdir);
656 
657  /* Config directory */
658  confdir = MatlabDocMaker.getPref(" confdir ",);
659  word = " keep ";
660  if isstruct(confdir) || isempty(confdir) || exist(confdir," dir ") ~= 7
661  confdir = fullfile(srcdir," documentation ");
662  word = " set ";
663  end
664  str = sprintf(" Do you want to %s %s as your documentation configuration files directory?\n(Y)es/(N)o?: ",word,strrep(confdir," \ "," \\ "));
665  ds = lower(input(str," s "));
666  if isequal(ds," n ")
667  d = uigetdir(confdir," Please select the documentation configuration directory ");
668  if d == 0
669  error(" No documentation configuration directory specified. Aborting setup. ");
670  end
671  confdir = d;
672  end
673  MatlabDocMaker.setPref(" confdir ",confdir);
674 
675  /* Output directory */
676  outdir = MatlabDocMaker.getPref(" outdir ",);
677  word = " keep ";
678  if isstruct(outdir) || isempty(outdir) || exist(outdir," dir ") ~= 7
679  outdir = confdir;
680  word = " set ";
681  end
682  str = sprintf(" Do you want to %s %s as your documentation output directory?\n(Y)es/(N)o?: ",word,strrep(outdir," \ "," \\ "));
683  ds = lower(input(str," s "));
684  if isequal(ds," n ")
685  d = uigetdir(outdir," Please select the documentation output directory ");
686  if d == 0
687  error(" No documentation output directory specified. Aborting setup. ");
688  end
689  outdir = d;
690  end
691  MatlabDocMaker.setPref(" outdir ",outdir);
692 
693  /* % Additional Project properties */
694  if isequal(lower(input([" Do you want to specify further project details?\n "...
695  " You can set them later using provided set methods. (Y)es/(N)o?: "]," s "))," y ")
696  MatlabDocMaker.setPref(" proj_ver ",input(" Please specify the project version, e.g. '0.1': "," s "));
697  MatlabDocMaker.setPref(" proj_desc ",input(" Please specify a short project description: "," s "));
698  MatlabDocMaker.setProjectLogo;
699  end
700 
701  /* % Check for necessary and recommended tools */
702  hasall = true;
703  setenv(" PATH ",[getenv(" PATH ") pathsep confdir]);
704  fprintf(" [Required] Checking for doxygen... ");
705  [st, vers] = system(" doxygen --version ");
706  if st == 0
707  fprintf(" found %s\n ",vers(1:end-1));
708  else
709  fprintf(2," not found!\n ");
710  hasall = false;
711  end
712  fprintf(" [Required] Checking for mtoc++... ");
713  ldpath = ;
714  if isunix
715  ldpath = " LD_LIBRARY_PATH= ";
716  end
717  [st, vers] = system(sprintf(" %smtocpp --version ",ldpath));
718  if st == 0
719  fprintf(" found %s\n ",vers(1:end-1));
720  else
721  fprintf(2," not found!\n ");
722  hasall = false;
723  end
724  fprintf(" [Recommended] Checking for dot... ");
725  [st, vers] = system(" dot -V ");
726  if st == 0
727  fprintf(" found %s\n ",vers(1:end-1));
728  else
729  fprintf(2," dot Graphviz tool not found!\nInstall dot for nicer class diagrams.\n ");
730  end
731  fprintf(" [Recommended] Checking for latex... ");
732  [st, vers] = system(" latex --version ");
733  if st == 0
734  fprintf(" found %s\n ",vers(1:strfind(vers,sprintf(" \n "))-1));
735  else
736  fprintf(2," latex not found!\nA LaTeX installation available on the system path is strongly recommended with mtoc++.\n ");
737  end
738  /* Ghostscript */
739  fprintf(" [Recommended] Checking for ghostscript... ");
740  if ispc
741  [st, vers] = system(" gswin32c --version ");
742  if st ~= 0
743  [st, vers] = system(" gswin64c --version ");
744  end
745  else
746  [st, vers] = system(" gs --version ");
747  end
748  if st == 0
749  fprintf(" found %s\n ",vers(1:strfind(vers,sprintf(" \n "))-1));
750  else
751  fprintf(2," ghostscript not found!\nCreating LaTeX formulas might not work properly.\n ");
752  end
753 
754  if ~hasall
755  fprintf(2," Please make sure all prerequisites can be found on PATH or copy the executables into %s.\n ",confdir);
756  fprintf(" <<<< MatlabDocMaker setup finished with warnings. >>>>\n ");
757  else
758  fprintf(" <<<< MatlabDocMaker setup successful. >>>>\nYou can now create your projects documentation by running <a href='matlab:MatlabDocMaker.create( "" open "" ,true)'>MatlabDocMaker.create</a>!\n ");
759  end
760  }
769  private: /* ( Static ) */ /* ( Constant ) */
770 
771  static function value = getProjPrefTag() {
772  str = regexprep(strrep(strtrim(MatlabDocMaker.getProjectName)," "," _ ")," [^\d\w] ",);
773  value = sprintf(" MatlabDocMaker_on_%s ",str);
774  }
784  static function value = getPref(name,default) {
785  if nargin < 2
786  def = [];
787  else
788  def = default;
789  end
790  value = getpref(MatlabDocMaker.getProjPrefTag,name,def);
791  if nargin < 2 && isempty(value)
792  error(" MatlabDocMaker preferences not found/set correctly. (Re-)Run the MatlabDocMaker.setup method. ");
793  end
794  }
795 
796 
797  static function value = setPref(name,value) {
798  setpref(MatlabDocMaker.getProjPrefTag,name,value);
799  }
800 
801 
802 };
803 
804 
A variable number of input arguments.
Speed test * all(1:3)
function varargout = ghostscript(cmd)
Initialize any required system calls before calling ghostscript.
Definition: ghostscript.m:17
#define Y(i, j)