Monday, April 27, 2009

Searching for keyword values in a text (configuration) file in R

Taken from :
https://stat.ethz.ch/pipermail/r-help/2006-September/113841.html

Question :
I would like to read values from an ASCII text file that contains information in the following format:

DEVICE = 'PC'
CPU_SPEED = '1999', '233'
...
How can I e.g. get R to read the 2nd value of CPU_SPEED?

Answer :

Read in data using readLines and replace
= with comma and delete all spaces.
Then reread using read.table and set the
rownames to column 1 removing column 1.

# test data
Lines0 <- "DEVICE = 'PC'
CPU_SPEED = '1999', '233'
"

# if reading from a file then
# replace next line with something like Lines <- readLines("myfile.dat")
Lines <- readLines(textConnection(Lines0))
Lines <- gsub("=", ",", Lines)
Lines <- gsub(" ", "", Lines)
DF <- read.table(textConnection(Lines), sep = ",", fill = TRUE,
colClasses = "character", header = FALSE)
rownames(DF) <- DF[,1]
DF <- DF[,-1]

DF["CPU_SPEED", 2]

Thursday, April 16, 2009

MySQL Command line

How do I import a MySQL dumpfile into my database?
From linux shell :
$mysql -u gocek_egroupware -p gocek_egroupware2_16 < gocek_egroupware_16_eski.sql

Wednesday, April 15, 2009

Making animations in Linux with ffmpeg and meconde

This information is taken from http://electron.mit.edu/~gsteele/

To make an animation from the image files, you may use mencode or ffmepg. Here, we will use mencode. First, all the images need to be converted to .jpg format :

In linux shell, type the following code :

for f in *png ; do convert -quality 100 $f `basename $f png`jpg; done

Then use encoder to create an avi file.

mencoder "mf://*.jpg" -mf fps=5 -o ModisTerra_Gocek.avi -ovc lavc -lavcopts vcodec=msmpeg4v2:vbitrate=800

I wanted my animation to display slower but setting the frame rate less than 5fps confused vlc, my favorite open source movie player (http://videolan.org) :

[00000420] avcodec decoder error: more than 5 seconds of late video -> dropping frame (computer too slow ?)

So I created the animation at 5 fps but reduced the playing speed from vlc.

It is also possible to view the animation with mplayer. Mplayer can even display a movie with a frame rate of 1 fps, no problems. One can adjust the move playing speed by pressing the [ and ] keys.