| 1 | |
|---|
| 2 | <!DOCTYPE html |
|---|
| 3 | PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"> |
|---|
| 4 | <html xmlns:mwsh="http://www.mathworks.com/namespace/mcode/v1/syntaxhighlight.dtd"> |
|---|
| 5 | <head> |
|---|
| 6 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> |
|---|
| 7 | |
|---|
| 8 | <!-- |
|---|
| 9 | This HTML is auto-generated from an M-file. |
|---|
| 10 | To make changes, update the M-file and republish this document. |
|---|
| 11 | --> |
|---|
| 12 | <title>textOut</title> |
|---|
| 13 | <meta name="generator" content="MATLAB 7.5"> |
|---|
| 14 | <meta name="date" content="2008-01-28"> |
|---|
| 15 | <meta name="m-file" content="script_textOut"> |
|---|
| 16 | <link type="text/css" rel="stylesheet" href="../../style.css"> |
|---|
| 17 | </head> |
|---|
| 18 | <body> |
|---|
| 19 | <p class="header">RWTH - Mindstorms NXT Toolbox</p> |
|---|
| 20 | <div class="content"> |
|---|
| 21 | <h1>textOut</h1> |
|---|
| 22 | <introduction> |
|---|
| 23 | <p>Wrapper for fprintf() which can optionally write screen output to a logfile</p> |
|---|
| 24 | </introduction> |
|---|
| 25 | <h2>Contents</h2> |
|---|
| 26 | <div> |
|---|
| 27 | <ul> |
|---|
| 28 | <li><a href="#1">Syntax</a></li> |
|---|
| 29 | <li><a href="#4">Description</a></li> |
|---|
| 30 | <li><a href="#10">Examples</a></li> |
|---|
| 31 | <li><a href="#16">Signature</a></li> |
|---|
| 32 | </ul> |
|---|
| 33 | </div> |
|---|
| 34 | <h2>Syntax<a name="1"></a></h2> |
|---|
| 35 | <p><tt>textOut(strMsg)</tt></p> |
|---|
| 36 | <p><tt>textOut(strMsg, 'screenonly')</tt></p> |
|---|
| 37 | <p><tt>textOut(strMsg, 'logonly')</tt></p> |
|---|
| 38 | <h2>Description<a name="4"></a></h2> |
|---|
| 39 | <p><tt>textOut(strMsg)</tt> will write to screen (command window) AND logfile, if global logging is enabled. |
|---|
| 40 | </p> |
|---|
| 41 | <p><tt>textOut(strMsg, 'screenonly')</tt> writes to screen (command window) only. |
|---|
| 42 | </p> |
|---|
| 43 | <p><tt>textOut(strMsg, 'logonly')</tt> writes to logfile only (global logging must be enabled). If logging is disabled or somehow failes, the message will not be |
|---|
| 44 | logged or displayed at all... |
|---|
| 45 | </p> |
|---|
| 46 | <p><b>Note:</b></p> |
|---|
| 47 | <p>To enable logging (to file), set the global var <tt>EnableLogging</tt> to <tt>true</tt> and set <tt>Logfilename</tt> to a valid filename. This function distinguishes between Windows and Linux systems to use proper linebreaks. The global variable |
|---|
| 48 | <tt>DisableScreenOut</tt> is an on/off switch for the complete textOut()-messages that would appear on the command window. Default setting is <tt>false</tt>, i.e. there will be no output. |
|---|
| 49 | </p> |
|---|
| 50 | <p>Recommended usage is together with sprintf(), in order to add linebreaks for example.</p> |
|---|
| 51 | <h2>Examples<a name="10"></a></h2><pre class="codeinput"> textOut(<span class="string">'This is a message\n'</span>); |
|---|
| 52 | </pre><pre class="codeinput"> x = <span class="string">'world'</span>; |
|---|
| 53 | y = 2007; |
|---|
| 54 | textOut(sprintf(<span class="string">'Hello %s, it is the year %d!\n'</span>, x, y)); |
|---|
| 55 | <span class="comment">%Results in: >> Hello world, it is the year 2007!</span> |
|---|
| 56 | </pre><pre class="codeinput"> <span class="keyword">global</span> EnableLogging |
|---|
| 57 | <span class="keyword">global</span> Logfilename |
|---|
| 58 | EnableLogging = true; |
|---|
| 59 | Logfilename = <span class="string">'logfile.txt'</span>; |
|---|
| 60 | textOut(sprintf(<span class="string">'Whatever I say here will be logged to the file as well.\n'</span>)); |
|---|
| 61 | </pre><pre class="codeinput"> textOut(sprintf(<span class="string">'Only appears in the command window\n'</span>), <span class="string">'screenonly'</span>); |
|---|
| 62 | </pre><pre class="codeinput"> textOut(sprintf(<span class="string">'Only appears in the logfile, if logging enabled\n'</span>), <span class="string">'logonly'</span>); |
|---|
| 63 | </pre><pre class="codeinput"> <span class="keyword">global</span> DisableScreenOut |
|---|
| 64 | DisableScreenOut = true; |
|---|
| 65 | textOut(sprintf([<span class="string">'If logging is enabled, this goes to the logfile, '</span>, <span class="keyword">...</span> |
|---|
| 66 | <span class="string">'if not, this goes nowhere\n'</span>])); |
|---|
| 67 | </pre><h2>Signature<a name="16"></a></h2> |
|---|
| 68 | <div> |
|---|
| 69 | <ul> |
|---|
| 70 | <li><b>Author:</b> Linus Atorf (see AUTHORS) |
|---|
| 71 | </li> |
|---|
| 72 | <li><b>Date:</b> 2007/10/15 |
|---|
| 73 | </li> |
|---|
| 74 | <li><b>Copyright:</b> 2007, RWTH Aachen University |
|---|
| 75 | </li> |
|---|
| 76 | </ul> |
|---|
| 77 | </div> |
|---|
| 78 | <p class="footer"><br> |
|---|
| 79 | Published with wg_publish; V1.0<br></p> |
|---|
| 80 | </div> |
|---|
| 81 | <!-- |
|---|
| 82 | ##### SOURCE BEGIN ##### |
|---|
| 83 | %% textOut |
|---|
| 84 | % Wrapper for fprintf() which can optionally write screen output to a logfile |
|---|
| 85 | %% |
|---|
| 86 | %% Syntax |
|---|
| 87 | % |textOut(strMsg)| |
|---|
| 88 | %% |
|---|
| 89 | % |textOut(strMsg, 'screenonly')| |
|---|
| 90 | %% |
|---|
| 91 | % |textOut(strMsg, 'logonly')| |
|---|
| 92 | %% |
|---|
| 93 | %% Description |
|---|
| 94 | % |textOut(strMsg)| will write to screen (command window) AND logfile, if global logging is |
|---|
| 95 | % enabled. |
|---|
| 96 | %% |
|---|
| 97 | % |textOut(strMsg, 'screenonly')| writes to screen (command window) only. |
|---|
| 98 | %% |
|---|
| 99 | % |textOut(strMsg, 'logonly')| writes to logfile only (global logging must be enabled). If logging |
|---|
| 100 | % is disabled or somehow failes, the message will not be logged or displayed at all... |
|---|
| 101 | %% |
|---|
| 102 | %% |
|---|
| 103 | % *Note:* |
|---|
| 104 | %% |
|---|
| 105 | % To enable logging (to file), set the global var |EnableLogging| to |true| and |
|---|
| 106 | % set |Logfilename| to a valid filename. This function distinguishes between |
|---|
| 107 | % Windows and Linux systems to use proper linebreaks. |
|---|
| 108 | % The global variable |DisableScreenOut| is an on/off switch for the |
|---|
| 109 | % complete textOut()-messages that would appear on the command window. |
|---|
| 110 | % Default setting is |false|, i.e. there will be no output. |
|---|
| 111 | %% |
|---|
| 112 | % Recommended usage is together with sprintf(), in order to add |
|---|
| 113 | % linebreaks for example. |
|---|
| 114 | %% |
|---|
| 115 | %% Examples |
|---|
| 116 | textOut('This is a message\n'); |
|---|
| 117 | %% |
|---|
| 118 | x = 'world'; |
|---|
| 119 | y = 2007; |
|---|
| 120 | textOut(sprintf('Hello %s, it is the year %d!\n', x, y)); |
|---|
| 121 | %Results in: >> Hello world, it is the year 2007! |
|---|
| 122 | %% |
|---|
| 123 | global EnableLogging |
|---|
| 124 | global Logfilename |
|---|
| 125 | EnableLogging = true; |
|---|
| 126 | Logfilename = 'logfile.txt'; |
|---|
| 127 | textOut(sprintf('Whatever I say here will be logged to the file as well.\n')); |
|---|
| 128 | %% |
|---|
| 129 | textOut(sprintf('Only appears in the command window\n'), 'screenonly'); |
|---|
| 130 | %% |
|---|
| 131 | textOut(sprintf('Only appears in the logfile, if logging enabled\n'), 'logonly'); |
|---|
| 132 | %% |
|---|
| 133 | global DisableScreenOut |
|---|
| 134 | DisableScreenOut = true; |
|---|
| 135 | textOut(sprintf(['If logging is enabled, this goes to the logfile, ', ... |
|---|
| 136 | 'if not, this goes nowhere\n'])); |
|---|
| 137 | %% |
|---|
| 138 | %% |
|---|
| 139 | %% Signature |
|---|
| 140 | %% |
|---|
| 141 | % * *Author:* Linus Atorf (see AUTHORS) |
|---|
| 142 | % * *Date:* 2007/10/15 |
|---|
| 143 | % * *Copyright:* 2007, RWTH Aachen University |
|---|
| 144 | % |
|---|
| 145 | |
|---|
| 146 | ##### SOURCE END ##### |
|---|
| 147 | --> |
|---|
| 148 | </body> |
|---|
| 149 | </html> |
|---|