Monday, June 30, 2008

Full Screen Figures in Matlab

Matlab's native figure command does not give you an option to make your figure full screen in 1 step. Instead first you have to find the screen resolution and then give your figure command the size of the screen.

First thing you want to do is:

screen_size = get(0, 'ScreenSize');

This will return a 4 element array: (left, bottom, width, height);
The ones we are interested are the "width" and "height".

Now we have the size of the screen, we can make our figure full screen:

f1 = figure(1);
set(f1, 'Position', [0 0 screen_size(3) screen_size(4) ] );

Now you should have a figure that is full screen.

Saturday, June 14, 2008

Changing the SMTP port number in Evolution

I started using evolution email client in Ubuntu. However, my service provider requires me to use a different port for SMTP. When you first check the tab where you set the options for SMTP, you can not find a field about the port number of SMTP. I was looking for a field because Thunderbird has a field for port.
The solution is this :

smtp.hostname.com --> Assumes you are using port 25.

smtp.hostname.com:587 --> You set the SMTP port to 587.

I think this is not a good way to handle ports, but I am happy since I found a soluton.

Wednesday, June 04, 2008

A simple problem with LLNL's VisIt

Recently I found the LLNL's visualization software called VisIt. It has many capabilities and the graphics looked promising from their screenshots. So I wanted to give it a try. However, I had a problem and found the solution with a trial and error way. Since VisIt is developed to be working on distributed systems and parallel systems, it is always using sockets to connect to its server part even you are using them on the same computer.

So when you call the main program with gui,

>visit.exe

It will generate the following commands

Running: "C:\Program Files\LLNL\VisIt 1.9.0\gui"
Running: "C:\Program Files\LLNL\VisIt 1.9.0\viewer" -geometry 1272x1020+408+0 -borders 22,4,4,4 -shift 4,22 -p
reshift 4,22 -defer -host your.hostname -port 5600
Running: "C:\Program Files\LLNL\VisIt 1.9.0\mdserver" -host your.hostname -port 5602

So if you are running it the first time, Windows will ask you to open the ports given above to be unblocked. I unblocked them.

Then suddenly at 32%, mdserver crashed.

After several forum messages and trials, I was still getting the same error.

Later, I installed VisIt to my home computer also and it worked without a problem. Therefore, I started looking for the differences between my two computers. The first and the most obvious difference was with the network connections. At my home computer I had VMWare installed. When you install VMWare, it creates several different network connections, which were enabled by default. Even though they are not real connections, VisIt still handled them according to their IP adresses.

Finally, I disabled all my network connections created by VMWare. Give one more try to VisIt and it started working.

I think the fix will be considered with the next release of VisIt.

Export figures in Matlab without displaying them

Assuming you have a lot of figures to plot, but you do not want to wait and see them in Matlab's figure window. There is a way you can export all of your figures without displaying them. This might also save you some time, since you are drawing them on the screen.

Here is how :

% Create a figure with visibility off
f = figure('Visible','off');
% Then do your plot
plot
% Finally export the plot as an image
print('-dpng', 'test.png');

You can also make this in a loop (Which is very probable if you have too many figures).
Do this

for i:1, n
f = figure('Visible','off');
plot
filename = sprintf('plot-%d',i);
print('-dpng', filename);
end

This will give you 'n' png images with your plots in it.

Tuesday, February 19, 2008

Timing background jobs to a file

If you are running a lengthy simulation or a compilation, sometimes you might have to close/logout of your terminal. However, if you just use the "time" command with out redirecting it is output to a file, you will not see the output of time command. For example you run a job and left terminal like following:

$>time ./my_job > my_job_output &

This will run "my_job" in the background and send its output to "my_job_output". If you do leave your terminal open, you will see your run time information on the terminal screen. However, if you close your terminal window, you will not see this information since your strerr is now not available.
For this purpose, you can send your program output and time output to different files. Then, even if you close your terminal, you will still see your time command output:

$> (time ./my_job >my_job_output) >& time.out &

This way you will run your job in the background, see your time command output and you can close your terminal.

Thursday, January 31, 2008

Convert ADCIRC grid to Tecplot data file

I created this utility to convert ADCIRC compatible grids in to Tecplot files. The program is written in Perl. I also added comments. If you need it, enjoy :). If you want to see the code it self you can look at this file.

Saturday, January 26, 2008

How to install LAMP on Ubuntu Gutsy Gibbon (Desktop Version)

If you are using Ubuntu Gutsy Gibbon (7.10) Desktop edition and you want to install the "LAMP" (actually you want to install AMP part :)). Just do the following:

Never forget this before installing something.

$>sudo apt-get update

and

$>sudo apt-get install apache2 libapache2-mod-php5 libapache2-mod-auth-mysql mysql-server php5 php5-mysql

You will be asked to type the mysql password for the "root" user. Pick something you would not forget :).

Viola, you should be able to access your setup in no time...

Very useful Gnuplot information



If you need a free and a powerful plotting program Gnuplot would be a good choice for you.


Especially if you are working on a Linux system, you might find many additional utilities making your life easier with Gnuplot.

Without the GUI front ends it will behave more like a command prompt. Also it is capable of reading script type of files and act accordingly.

There are a lot of good Gnuplot tutorials and help pages all over the internet. However, I think this page (not so Frequently Asked Questions) about Gnuplot goes beyond the regular help pages. There are many specific cases, but there are also many generic help.

You can even plot a butterfly with Gnuplot :). (generated using this script from Gnuplot website)

Enjoy your plots...

Monday, January 21, 2008

Creating DVD from your video files on Linux

Linux has many different programs for editing video and creating DVDs from your individual video file collections. The ones I know and use include:
and probably many more. Most of these programs have many features besides the video editing capabilities. Some of them might do the same things in different or more efficient ways.

I am not really an expert on video editing or creating DVDs. However, from different sources I gathered a lot of useful information to do what I need. My basic need was to create DVDs from my video files. I also wanted to have fancy DVD menus showing the preview of the videos, which is probably a good thing to have on DVDs.

For this purpose my main tool is actually videotrans. Videotrans is a collection of utilities (movie-to-dvd, movie-title, movie-make-title etc.) to create DVD compatible video/audio files, creating animated/static title menus, creating dvdauthor compatible XML files etc. Videotrans utilities are mostly complex shell scripts using some of the utilities I mentioned above and some more. I am sure there are more fancy programs to create DVDs and probably some of them are free/open source. However, I am currently using Videotrans because for the last 2 years I really got professional with it. I will not it is superior and very good. I had many problems that is for sure, but for the time being I can find my way out and create my DVDs.

Yesterday, I found a new program called, KDE DVD Authoring Wizard. The program seems to be doing the same thing with Videotrans in a more fancy KDE Wizard way, which is good. However, from my initial tests, and initial research it seems to have the same limitations with Videotrans. I will definitely look more in to it in the future (Also I had some problems because it is a KDE type utility and I use Gnome on Ubuntu).

I will try to demonstrate a little DVD creation example here using the Videotrans utilities.
Ok, for this demonstration I am assuming you have 2 long video files (with mpg extensions) and a small video (or part of a big video) to be used as title menu background animation.

Step 1 - Install Videotrans:
Because videotrans is actually a set of shell scripts (mostly), the installation is pretty straight forward. Download the latest videotrans archive from its website and unpack the file you obtained. Go in to the videotrans directory and do:

$>./configure
$>make
$>make install

You have to be superuser to install the program. Also for small utilities included in the set, you need to have a GCC installed.

Assuming you did not have problems with installation (I did not and it is one of the easiest installations I did), we can move on to creating some DVDs.

Step 2: Making your video files DVD compatible (if they are not) :
I am not really sure what a DVD compatible video is and I did not really make a research on that.However, I know I had to create the DVD compatible videos every time I created a DVD. So our first utility from videotrans set is movie-to-dvd:

$> movie-to-dvd -m "ntsc" -O "-nolirc" test.mpg

This command with the appropriate options will create to new files "test.m2v" and "test.ac3" from your home video "test.mpg". There other options available for use, but these are generally enough for me.
-m option defines which viewing mode you are using (PAL or NTSC). Since I am in US, my videos are NTSC. I think PAL is for European countries. You can find that in the man page.
-O option is to pass command line options to mplayer which is used by movie-to-dvd. And "-nolirc" parameters is to tell mplayer not to care about the remote control activities (Since I have a mythtv box on the same computer, remote control might interfere with mplayer). Now we are up to creating title.

Step 3 - Making a title:
Title in DVD is the first menu screen with buttons you get (Like previews, options etc.). In videotrans there are couple options for making the title of DVD. It can be a colored background with some kind of sound file or it can be an animated background(movie-make-title-simple) with animated previews (Picture in Picture type) (movie-make-title). I usually go for the fancy stuff :), so I am using the animated titles and I will describe creating animated titles (since it is harder to do :)).

Ok, so pick a video that you want to use in the main title of DVD. It does not have to be short, since you can get any part of any video, but I suggest keep your title video short, since it will go through a very long process.

$>movie-make-title -o title -s 10 -e 30 -m "ntsc" your_title_video.mpg

This command will generate a whole bunch of images in a subdirectory called title (-o title) and the sounds from that file in to a title.wav file.
-o title means it will create the output in a directory called "title"
-s 10 means your background animation for title will start at 10th second of the video.
-e 30 means your background animation for title will end at 30th second of the video.
-m "ntsc" same as the movie-to-dvd option, to indicate your video mode.
The important thing here is to keep in mind that the times you get from your video might be slightly differ when you generate the title images using the above command. So after generating images check your images and if needed run the above command again with adjusted times. Also keep in mind that, assuming 25 frames per second, you will end up with approximately 500 images after this operation and that is why I suggested keeping the title animation short :).

Step 4 - Making title video:
Since we have a plausible sequence of title images, we can go on and generate our title with the animated previews. I want to give a brief explanation about why images are used for title. Since we want to create a title with animated background and video previews in the front, we have to somehow overlay these videos on top of each other. And I guess the overlaying images is the easiest way to do this :). So in the end what will happen is our main video (test.mpg) frames will be overlaid with the title images created above. Then animating the new series of images will create a new video of overlaid videos.

$>movie-title -o title.vob -t title -s 5 -c 5 test.m2v

-o title.vob tells program to create the DVD title in a file named "title.vob" which is compatible with DVD.
-t title means use the images from the "title" directory to create the background animation.
-s 5 means start the PIP preview of videos from 5th second of the video
-c 5 means create chapters for DVD every 5 minutes. (be careful this is minutes).
and use test.m2v video created above to create your PIP preview.
There is another option(-T XxY) for how the videos are placed on the screen. If you do not give this option, it will place the PIPs in a reasonable way (Regular grid. I like it).

We are close to the end. I bet you can already see the your results (or not :)).
This is the tricky part, because this is where all the images are overlaid using ImageMagick program (convert). And this is why it is tricky. ImageMagick is a very powerful set of image processing tools. However, as far as I know, they keep changing the command line options from version to version. Therefore, for people using ImageMagick, it becomes tricky to do same job with different versions. I will not really get deep, but if you start to see just black screens with your video file name on it, it is probably due to a version incompatibility with ImageMagick (Suggested is upgrade/downgrade ImageMagick, after making sure everything else is working :)).

If you want to add information about your videos to the menu, videotrans is capable of adding an information button. I think it is designed for giving information on TV show episodes, but I think it can be used for general information for your videos. The only trick is to place your information in a text file with ".info" extension in the same folder with your video. So your info file should be "test.info" for the "test.mpg" video file. movie-title automatically checks this files and creates the necessary images for the information display.

Step 5 - Final step-Create the DVD using dvdauthor:
Once you successfully see the end of the above step, it will tell you how to create your DVD using dvdauthor. Actually all it does is, give you the command to run depending on your file names. The command will look like this after above step:
"dvdauthor -o dvd_directory -x title.vob-dvdauthor.xml"
The xml file is for dvdauthor to process and join the videos/sounds/titles etc.

$>dvdauthor -o dvd_directory -x title.vob-dvdauthor.xml

This will give you a directory name "dvd_directory" with your DVD created in it. Now all you have to do is, burn your dvd_directory to an actual DVD. However I strongly recommend that check your end results. For the first times I had many unwanted errors/problems and end up burning useless DVDs.

So, for burning, I first create and iso image and then burn it using K3B.

$>mkisofs -o dvd.iso dvd_directory/

This will create a file called "dvd.iso" using the "dvd_directory" create above.

Then you can simply burn your iso file.

That should make it all, stick your DVD in to a DVD player and enjoy...

Sunday, January 20, 2008

Debugging shell scripts

Sometimes you might need to debug or see what is really running in your shell script. If you want to see each line/command executed simply add "-x" to your first line where you define your shell/interpreter. This will output every executed command with a "+" before the line.

#! /bin/sh -x
echo "Hello World!"

This will output :

+echo "Hello World!"
Hello World!

I know this works with sh and bash, but I do not know the other shells.

Also debugging especially long shell scripts can be a hard job. If you set the "-x" option at the beginning of the script, then it will output all the commands executed.
For this purpose, you can add "set -x" before the place you want to debug and "set +x" at the end.

#! /bin/sh
echo "This is the test"
set -x
echo "Only show this part"
set +x

This will output:

This is the test
+echo "Only show this part"
+set +x
Only show this part


Also if you want to run your script, but not execute the commands you can use the -n option. This is best for checking your syntax.
Happy debugging with your favorite shell.

Friday, January 18, 2008

Small changes with Emacs

Emacs is a great editor with many different capabilities. One of the best features of Emacs is that it is highly configurable. There are several default settings that I use with Emacs in the configuration file. I will give only a couple of them. You can put these in to your local Emacs configuration file ".emacs" or ".emacs.d/.emacs" which might depend on your system.

To change your background and foreground colors to black and white:

(set-background-color "Black")
(set-foreground-color "White")

To change the cursor color:

(set-cursor-color "White")

To stop Emacs from creating auto backup files:

(setq make-backup-files nil)

There are many more options and settings you can change with Emacs. Try and enjoy it. Welcome to the world of Emacs :).

Wednesday, January 16, 2008

Mass substitution with Perl Command Line

For changing all occurrences of a several expression in a file, Perl with command line options can be very helpful. The following shows a pretty general example:

$> perl -i.bck -ep 's/search_term/replace_with/g' filename

The above command will check the "filename" file and, replace all occurences of "search_term" with the "replace_with" term. "-i" option tells Perl to backup the file with a ".bck" extension before any operation.

Maximum zone limit in Tecplot

To change the maximum number of zones used in Tecplot ASCII data files, the limits might need to be changed. The limit can be changed with:

$!LIMITS

MAXPREPLOTZONES = (Number)

The change has to be added to the Tecplot configuration file.

Creating an image from a TeX file

To create an image from a Latex file do the following :

$>latex --interaction=nonstopmode file.tex

$>dvips -E file.dvi -o file.ps

$>convert -density 200 file.ps file.png

Violaaaa;

Note that convert is a command line utility that comes with ImageMagick installation.

Monday, January 14, 2008

Replacing certain values in matlab vectors

In Matlab if you need to replace certain values with a single value you can simple do this,

>u(find(isnan(u))) = [];

Using this will find and remove all the NaN (Not a Number) values.

If you want to remove any value you can simple use find again,

>u(find(u=9999)) = [];


This will remove all the values of u = 9999.

Be aware that applying this will make your vector shorter if there is any value removed.

Monday, January 07, 2008

Manually install Perl modules with CPAN.pm

From your shell run

$> perl -MCPAN -e shell

command, it will ask you a few questions. Answer the questions, which are the basic settings for the local installation directory. You can set it up to a local directory within your home directory. Then simply type the following to install any module.

$> install Date

will install the latest Date module for Perl.

For further details see CPAN web site