Thursday, December 11, 2008

A few helpful emacs tweaks

I find them randomly on the web, or in the Emacs manual. Add these line in the .emacs file in your home directory, you'll get the desired feature.
  ;; turn off scroll bar
(toggle-scroll-bar 0)

;; don't show toolbar
(tool-bar-mode 0)

;; disable menu bar
(menu-bar-mode 0)

;; do not display a splash screen on startup
;; only needed for emacs 22+
(setq inhibit-splash-screen t)

;; disable side fringe
;; this only works for emacs 22+
(set-fringe-mode 0)

;; toggle full screen
(defun switch-full-screen ()
(interactive)
(shell-command "wmctrl -r :ACTIVE: -btoggle,fullscreen"))
(global-set-key [f11] 'switch-full-screen)
The last full screen function using the wmctrl utility:
  sudo apt-get install wmctrl
You can also use Emacs' own frame control to go full screen:
  (defun fullscreen ()
(interactive)
(set-frame-parameter nil 'fullscreen
(if (frame-parameter nil 'fullscreen) nil 'fullboth)))
(global-set-key [f11] 'fullscreen)
But the window will be maximized after toggling back.
  ;; define the compile command to be make filename.o, and bind to C-x c
(setq compile-command '(concat "make "
(file-name-sans-extension (file-name-nondirectory buffer-file-name))
".o"))
(global-set-key "\C-xc" 'compile)

By the way, my new Eee 901 died today, after 30 hours being in my hands. Bad luck or bad quality? Luckily TigerDirect allow me to send it back and replace it. We will see how the next one doing.

Wednesday, December 10, 2008

Install xubuntu 8.10 on eee 901

Got my WindowXP eee901 today. Actually, it arrived in a *pink* box.

First impression: It's really small, especially when viewing it side by side with my T61. The keyboard is indeed small, and some keys are in unconventional places. But the feeling of key strokes is not bad. The screen is matte rather than glassy finishing, which I really like. Unfortunately, the outside of the screen panel is polished, which I don't really like.

Now the important thing: take off the Windows XP sticker and put the xubuntu 8.10 on it. There are quite a few tutorials online on this, just name a couple:

http://thanhsiang.org/faqing/node/116
http://tombuntu.com/index.php/2008/11/17/installing-ubuntu-810-on-the-eee-pc-901/

A side notes. When I tried to make the first flash drive live disk a few days back, I ended up with a stick which didn't boot. The complaint is "No operating system found". I came across a post in some forum (I tried hard to locate it today, but not able to) saying about the same problem, and the fix is to use the testdisk utility to fix disk errors (MBR, partition table etc). So I installed the utility:
  sudo apt-get install testdisk
and it did the job. Now I have a bootable xubuntu stick made with the usb-creator program come with ubuntu 8.10, and ready to purge the XP.

Step 1: Install xubuntu 8.10 on the eee 901.

i) The flash drive is treated as hard drive rather than Removable drive in the eee's BIOS. So you should find it in the HDD boot device menu.

ii) The installer window is a little big bigger than eee's screen and buttons might be missing. Maximizing the window solves the problem.

iii) Disk partition. The eee 901 has a 4GB primary and a 8GB(windows) or 16GB(linux) secondary SSD. I formated the 4GB one to ext2 and used it for the root file system. The secondary SSD is also formated into a single partition and mounted at /home. This way, your home directory is untouched anytime you want to reinstall the system. I didn't make any swap partition since SSD is slow, and frequent reading/writing might do a lot of harm to the disk. The installer will complain about this, just ignore it.


After the installer has done its job, unplug the flash drive and boot into the new system. Wireless network does not work at this point, but the wired LAN works.

Step 2. Install the array.org kernel.

Follow their instructions to install either the stable eeepc kernel or the eeepc-lean kernel. Reboot, the wireless network and most other hardwares now work.

Step 3. Install eee-control, which will make life a little bit easier.

Step 4. Tombuntu provides a few helpful tweaks.

Step 5. Remove preinstalled useless packages, upgrade, and install wanted packages, -- the usual thing.

Bash one-liner: batch rename

Here is a bash recipe to rename files in batch. It can also be used to retag mp3 files according to their file names.
for a in *; do b=`echo $a|sed 's/.*\([0-9][0-9]*\).*\(\..*\)$/\1\2/' `; mv "$a" "$b"; done
In this example, all files are renamed to the first collection of numbers in its original names, while keeping the original postfix. E.g.,
blue4.mp3 -> 4.mp3
11help.dat -> 11.dat

Monday, December 8, 2008

Why Asus eee 901?

I ordered a black Asus eee 901 last week, and it should arrive in two days. Here I make some notes on how I decided on the Eee.

Reference reviews:
http://portablemonkey.com/article/asus-eee-pc-901-vs-acer-aspire-one-vs-dell-mini-9/
http://www.youtube.com/watch?v=0CuxV-jsrk8
http://blog.laptopmag.com/asus-eee-pc-901-mini-review
http://www.slashgear.com/asus-eee-pc-901-linux-edition-review-2412220/
http://www.brighthand.com/default.asp?newsID=14238
http://www.t3.com/news/netbook-spec-showdown-acer-aspire-one-asus-eee-pc-901-dell-inspiron-mini-9-hp-mini-note-msi-wind-and-lg-x110?=36605

I have tired of carrying my Thinkpad T61 to conferences after a few trips, and news comes that everyone is making 9" "netbook" now. I read about Asus' news release before their first Eee PC a year ago, but a 7" screen on a 9" frame discoraged me. Now the 9-inches comes out and it's time for me to jump in. In fact, I have quite a few to choose from: Asus Eee 901, Acer Aspire One, Dell Mini 8, HP 2133 MiniNote.

First thing first, what I'm looking for in a tiny computer?

i) able to run Linux. All four models have linux version, so this is not a problem.

ii) using SSD rather than magnetic HD to save weight (sorry, HP). HD capacity is not very import to me -- I'm not going to carry all the simulation data with me, and a few Gig for programming and document writting is enough. In this case, the added weight and vunerability is a big minus.

iii) size and weight. The wasted boarder on the screen panel does not make any sense to me, although this would allow a slightly bigger keyboard. In this regard, the HP is the worst, followed by the Acer.

iv) Battery life. The Eee comes with 6-cell battery, which might last 6-7 hours. The Aspire also has a 6-cell battery option, but only with the HDD version. Dell and HP come with 4-cell and 3-cell, which is not good although the Dell weighs less. However, 1.04kg and 1.1 kg do not really make a difference when sitting on your knees; the added 3 hours' more computing time is much more attractive.

v) Intel Atom processor preferred. Intel's latest processor consumes less power, yet it's performance comprimises little. Again, no HP.

vi) upgradable/expandable. 12-16 Gig of SSD is probably not enough, and 1GB of memory is definitely not.

vii) display resolution. For a 8.9" screen, 1024x600 is enough. The HP has a 1280x800 screen, but you will most like using a larger font to make it readable. It's a plus, but only by a little bit.

viii) I hate glassy coating on any computer screen. This pretty much rules out everyone except the Eee.

So now,
HP 2133 MiniNote: no SSD version, using non-Atom processor, large, short battery life;
Acer Aspire One: glassy finishing, large, short battery life;
This two are out of question, which leave me with
Dell Mini 8: glassy finishing, short battery life but light;
Asus Eee 901: heavy but much longer battery life;

First of all, why any one still want to buy from Dell? Besides, the 12GB version of Eee 901 was on sale at Tigerdirect.com at the time of my purchase ($350), and M$ live search gives 10% cashback. I would very like to get the 20GB linux version, but it's $150 more. I also ordered a 2GB kingston memory and a 8GB A-Data SDHC card from the Egg for the total of $30. These should meet my immediate need.

One of the biggest complaint about the Eee in most reviews is its undersized keyboard. Many people claim that they have to resolve to two-finger typing. Although my hands are not huge, they are not tiny either. We will see how it feels.

Useful links:
http://www.bit-tech.net/hardware/2008/06/17/inside-the-eeepc-901-investigating-atom/1

Mixed C++ and Fortran programming

This note is for compiling C++ and Fortran code. For general language issues concerning mixed programming, check out these references:
http://www.physiology.wisc.edu/comp/docs/notes/not017.html
http://www.math.utah.edu/software/c-with-fortran.html

All individual sources should be compiled into object files by using the "-c" compiler option. Here is how to link these ".o" files. I assume that the main program is in C and a few Fortran subroutines are called.

In gcc-4.0:

".o" from Fortran code is treated the same as those from C++ code. So just use the normal link command:
  g++ $(C_FLAGS) $(COBJS) $(FOBJS) $(LIBS) -o $(EXE)

In gcc-3.0:

Same as the 4.0 version, but the code must be linked against libg2c:
  g++ $(C_FLAGS) $(COBJS) $(FOBJS) $(LIBS) -lg2c -o $(EXE)

In icc:

Fortran compiler, rather than c++ compiler must be used. The option "-nofor_main" tells the compiler that there is no Fortran main subroutine; "-cxxlib" means to link to the C++ libraries.
  ifort -nofor_main -cxxlib $(COBJS) $(FOBJS) $(LIBS) -o $(EXE)

g77, gfortran, and ifort

Recently I have to combine my C++ code with the Fortran code from my colleague, and I soon find the complication with the gcc compilers. The Fortran code was written in F77, with a few exceptions when f90 syntax is used. It compiles well with g77, coming with pre-4.0 version of the gcc compilers. gcc 4.0 ships with gfortran rather than g77. gfortran is a Fortran 95 compiler, which is supposed to comile Fortran 77 codes as well, but not for the code I have. Fortunately, I'm able to compile the code with gfortran by some simple changes:

In Fortran 90/95, a "&" at the end of a line, or in the front of a line, is treated as line continuation sign. But in Fortran 77, it has to be a character at the sixth column. In the code I get, most "&"'s comply to the Fortran 77 format, but some are not. So I move all "&"'s to the sixth column, and now the code compile with gfortran.

I also need to compile the code with ifort on a different computer. The only thing that is different from gfortran is one compile option. The fortran code has long lines occasionally (allowed in Fortran 90/95 since its's free format). With g77 or gfortran, the compiler option "-ffixed-line-length-none" does the trick. But this option is not available in the Intel compiler. Fortunately, the long lines in the code is not terribly long, and "-132" option for ifort works. This option assumes the field width to be 132 columns rather than the standard 72 columns.

Makefile to work with both icc and gcc

I need to compile my code with gcc on some computer, but icc on others. So I dig a little bit and come up with this makefile to comply with both compiler with minimum change. The trick here is that GNU make can have conditional expressions, which I don't know before.

Reference: http://www.gnu.org/software/make/manual/make.html

Makefile:


#COMP = intel

C_FLAGS= -g -Wall
#C_FLAGS = -O2

BIN_DIR= $(HOME)/local/bin
NLIB = $(HOME)/proj/nlib

CXX = g++
F77 = gfortran
CXXFLAGS = $(C_FLAGS)
F77FLAGS = $(C_FLAGS) -ffixed-line-length-none
ifeq ($(COMP),intel)
CXX = icc
F77 = ifort
CXXFLAGS = $(C_FLAGS)
F77FLAGS = -O2 -132
endif

EXE = toi

...

# link

$(EXE): $(OBJS)
ifeq ($(COMP),intel)
$(F77) -nofor_main -cxxlib -o $@ $(OBJS) $(FLIBS)
else
$(CXX) $(CXXFLAGS) -I$(NLIB) -MMD -o $@ $(OBJS) $(FLIBS)
endif

First post

I finally set this blog up. Here I'll post tricks to get your computer to work, or to get it to work better. Many of tricks may be found elsewhere on the web, so the main purpose is for my own reference.

Here are what I have, and also the subjects that I will blog on:

Thinkpad T61 w/ xubuntu
Eee 901 w/ xubuntu (soon to have)
Shuttle XPC w/ xubuntu
Dell Inspiron 530 w/ Fedora (at work, maintained by someone else)

I do numerical simulations for work and program in C++ and python, occasionally in Fortran and Perl.
 
Creative Commons License All contents on this page are licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.