Wednesday, July 29, 2015

How to Handle Files with Scilab on Ubuntu 15.04

https://www.howtoforge.com/tutorial/scilab-file-handling

Scilab is an OpenSource Linux software for numerical computation similar to Matlab. This tutorial shows how to load data from files into Scilab for later use or processing. Scilab will interpret the code in the file and it's structure and format, etc. To use a file within the Scilab environment, it is necessary to use a number of previous commands that allow both reading and interpretation of the file in question.
You haven't installed scilab yet? Please see our Scilab installation tutorial.

Opening Files with the mopen command

This command opens a file in Scilab. The sequence is:
[fd, err] = mopen(file [, mode, swap ])
The meaning for each argument is:
File: A character string containing the path of the file to open.
Mode: A character string specifying the access mode requested for the file

Swap: A scalar swap is present and swap = 0 then automatic bytes swap is disabled. The default value is 1.

Err:  Returns a value that indicates the following errors:
Error Value Error Message
0 No error
-1 No more logical Units
-2 Cannot open file
-3 No more memory
-4 Invalid value
-5 Invalid Status

Fd: a positive integer, indicates a file descriptor.

Example Opening Files in Ubuntu Using Scilab

Now, we are going to open a MS Word Document using de mopen command
[fd, err] = mopen('/home/david/Documentos/Celestron Ubuntu.docx')
Please note that we didn´t use any additional argument, only for opening purpose.



Note:  In the Variable Browser we can find all the variable created including fd.


Parameters in mode Argument

The parameters are used to control access to the stream. The possible values are:

r: Opens the file for reading purposes.

rb: Opens the binary file for reading.

rt: Opens a text file for reading.

w: Creates a new file for writing. Also truncates the actual file to zero length.

wb:  Creates a new binary file for writing. Also truncates the actual file to zero length.

wt:  Creates a new text binary file for writing. Also truncates the actual file to zero length.

a or ab:  Appends writing to opened file to the end.

r+ or r+b: Opens a file for update.

w+ or w+b:  Truncates to zero length or creates a new file for update.

a+ or a+b: Appends.

Example Opening Files with parameters in Ubuntu Using Scilab


In this example, we are going to create a text file and write a line on it.

Type:
[fd, err] = mopen('/home/your name/test.txt', 'wt' );
mputl('Line text for test purposes', fd);



Note that if we have finished working with the file that we created, we have to close it using the mclose command. Later in this tutorial we try mclose command syntax.
mclose (fd);

Then we can search for the file in the directory:



Open the file:



This is useful if we are going to retrieve data from an external source, just like a data acquisition interface. We can load data from a txt file and then use this for processing.

Closing Files. mclose command.

Mclose must be used to close a file opened by mopen. If fd is omitted mclose closes the last opend file. mclose('all') closes all files opened by file('open',..) or mopen. Be careful with this use of mclose because when it is used inside a Scilab script file, it also closes the script and Scilab will not execute commands written after mclose('all').

Reading and using a text file content.

Sometimes we need to read and use the content of a txt file, either for reasons of data acquisition or for word processing. For reading purposes, we will use the command mgetl.

The Command mgetl

The command mgetl reads a line or lines from a txt file.

Syntax

txt=mgetl(file_desc [,m])

Arguments


file_desc: A character string giving the file name or a logical unit returned by mopen.

m: An integer scalar. The number of lines to read. The default value is -1.

txt: A column vector of string.

Examples using mgetl

With the file created before we can type:
>fd=mopen(/home/david/test.txt', 'r')
>txt=mgetl(fd,1);
>txt
>mclose(fd);

Note: We used the argument 'r' because we only need to read the file. A file cannot be opened for reading and writing at the same time. We set the argument 1 in mgetl for reading the first line only and don´t forget to close the file with mclose. The content of the first line is stored in a 'txt' string type variable.


There are many advanced commands that will be treated in further tutorials.

References

  1. Scilab Help Online, "https://help.scilab.org/". Retrieved at 06/30/2015.

Monday, July 27, 2015

How to enable logging in Open vSwitch for debugging and troubleshooting

http://ask.xmodulo.com/enable-logging-open-vswitch.html

Question: I am trying to troubleshoot my Open vSwitch deployment. For that I would like to inspect its debug messages generated by its built-in logging mechanism. How can I enable logging in Open vSwitch, and change its logging level (e.g., to INFO/DEBUG level) to check more detailed debug information? Open vSwitch (OVS) is the most popular open-source implementation of virtual switch on the Linux platform. As the today's data centers increasingly rely on the software-defined network (SDN) architecture, OVS is fastly adopted as the de-facto standard network element in data center's SDN deployments.
Open vSwitch has a built-in logging mechanism called VLOG. The VLOG facility allows one to enable and customize logging within various components of the switch. The logging information generated by VLOG can be sent to a combination of console, syslog and a separate log file for inspection. You can configure OVS logging dynamically at run-time with a command-line tool called ovs-appctl.

Here is how to enable logging and customize logging levels in Open vSwitch with ovs-appctl.
The syntax of ovs-appctl to customize VLOG is as follows.
$ sudo ovs-appctl vlog/set module[:facility[:level]]
  • Module: name of any valid component in OVS (e.g., netdev, ofproto, dpif, vswitchd, and many others)
  • Facility: destination of logging information (must be: console, syslog or file)
  • Level: verbosity of logging (must be: emer, err, warn, info, or dbg)
In OVS source code, module name is defined in each source file in the form of:
1
VLOG_DEFINE_THIS_MODULE();
For example, in lib/netdev.c, you will see:
1
VLOG_DEFINE_THIS_MODULE(netdev);
which indicates that lib/netdev.c is part of netdev module. Any logging messages generated in lib/netdev.c will belong to netdev module.
Depending on severity, several different kinds of logging messages are used in OVS source code: VLOG_INFO() for informational, VLOG_WARN() for warning, VLOG_ERR() for error, VLOG_DBG() for debugging, VLOG_EMERG for emergency. Logging level and facility determine which logging messages are sent to where.
To see a full list of available modules, facilities, and their respective logging levels, run the following commands. This command must be invoked after you have started OVS.
$ sudo ovs-appctl vlog/list

The output shows the debug levels of each module for three different facilities (console, syslog, file). By default, all modules have their logging level set to INFO.
Given any one OVS module, you can selectively change the debug level of any particular facility. For example, if you want to see more detailed debug messages of dpif module at the console screen, run the following command.
$ sudo ovs-appctl vlog/set dpif:console:dbg
You will see that dpif module's console facility has changed its logging level to DBG. The logging level of two other facilities, syslog and file, remains unchanged.

If you want to change the logging level for all modules, you can specify "ANY" as the module name. For example, the following command will change the console logging level of every module to DBG.
$ sudo ovs-appctl vlog/set ANY:console:dbg

Also, if you want to change the logging level of all three facilities at once, you can specify "ANY" as the facility name. For example, the following command will change the logging level of all facilities for every module to DBG.
$ sudo ovs-appctl vlog/set ANY:ANY:dbg

How to run DOS applications in Linux

https://www.howtoforge.com/tutorial/run-dos-application-in-linux

Chances are that most of you reading along those lines have started your “adventure” in computers through DOS. Although this long deprecated operating system is only running in our memories anymore, it will always hold a special place in our hearts. That said, some of you may still want to drink a sip of nostalgia or show your kids what old days were like by running some MS-DOS applications on your Linux distribution. The good news is, you can do it without much effort!
For this tutorial, I will be using a DOS game I was playing when I was a little kid called “UFO Enemy Unknown”. This was the first ever squad turn-based strategy game released by Microprose a bit over twenty years ago. A remake of the game was realized by Firaxis in 2012, clearly highlighting the success of the original title.

Wine

Since DOS executables are .exe files, it would be natural to think that you could run them with wine, but unfortunately you can't. The reason is stated as “DOS memory range unavailability”.
What this means is that the Linux kernel forbids any programs (including wine) from executing 16-bit applications and thus accessing the first 64k of kernel memory. It's a security feature and it won't change, so the terminal prompt to use DOSBox can be the first alternative option.

DOSBox

Install DOSBox from your Software Center and then open your file manager and make sure that you create a folder named “dosprogs” located in your home directory. Copy the game files inside this folder and then open dosbox by typing “dosbox” in a terminal. Now what we need to do is to mount the “dosprogs” folder into dosbox. To do this type mount c ~/dosprogs and press enter on the DOSBox console. Then type c: to enter the newly mounted disk as shown in the following screenshot.
You may then navigate the disk folders by using the “cd” command combined with the “dir” until you locate the game executable. For example, type “cd GAME” to enter the GAME folder and then type “dir” and press enter to see what the folder GAME contains. If the file list is too long to see in a screen, you may also give the “dir /w/p” command a try. In my case, the executable is UFO.bat and so I can run it by typing its name (with the extension) and pressing enter.

DOSemu

Another application that allows you to run DOS executables under Linux is DOS Emulator (also available in the Software Center). It is more straight forward in regards to the mounted partitions as you simply type “D:” and enter on the console interface to access your home directory. From there you can navigate to the folder that contains the DOS executable and run it in the same way we did in DOSBox. The thing is though that while DOSemu is simpler to use, it may not run flawlessly as I found through my testing. You can always give it a try though and see how it goes.