Monday, 8 September 2008

Oh Fortran, how I love thee.

Fortran's logical operators that operate on integers happen to be bitwise. I didn't care about this until now. Here's a summary for two integers, a and b, which can take values 0 or 1.

logical AND:






(ab)iand(a,b)
000
010
100
111

logical OR:






(ab)ior(a,b)
000
011
101
111

logical XOR:






(ab)ieor(a,b)
000
011
101
110

logical NOT:




(a)not(a)
0-1
1-2

WTF? I have been bitten by the bitwise bear! In order to get zeros and ones, I must use ieor(1,a) instead of not(a). Pah.

Also, the tables in this post look all shit in my browser but I can't be bothered to fix them when I have Fortran to do instead.

Today's post was brought to you by the numbers 0 and 1 and the letter F.

Monday, 19 May 2008

Installing an Epson scanner under Mandriva

Another how-to, brought to you by Mr B.:

To install and use the Epson Perfection 2480 scanner under Mandriva:

1) install "sane" (in package manager, install "libsane", "sane-backends" and perhaps "sane-frontends").

2) login as root, go to /etc/sane.d/ and edit the file "dll.conf" and ensure the line "snapscan" is uncommented (without a # at the beginning of the line).

3) from the CD supplied with the scanner, find the file "ESCAN/ModUsd.cab" and copy to your desktop (or elsewhere!).

4) go to the directory on your hard drive containing "ModUsd.cab" and run

$ cabextract ModUsd.cab

cabextract is a program to extract files from a micro$oft .cab format, which I have described in a previous post.

5) login as root and copy the firmware file "Esfw41.bin" to /etc/sane.d/esfw41.bin

6) run the following (as root):

$ scanimage -L

...and the scanner should be detected!

7) use "Kooka" or "Xscanimage" to use scanner (Xscanimage is from the package "sane-frontends")

Extracting Micro$oft .cab files

Here it is, courtesy of Mr B.:

To extract Microshite .cab files, install "cabextract" (from package manager).
Copy blah.cab into a directory and:

$ cabextract blah.cab

OR

$ cabextract -l blah.cab

to list the files in the .cab.

Friday, 16 May 2008

Fixing dvips

We have a lovely shiney (the case really is!) new computer named Lewis. (This is after Lewis Hamilton, because he is so fast).

Anyway, it was super fast to build and amazingly the whole kit works, even the processor fan started so our new core2duo didn't melt. Mandriva 2008.1 installed quicker than it takes our old laptops to boot up. Now I have to iron out all the little problems getting things to work. (Like why Firefox is thinking every word in the english language that I'm typing is spelt wrong!!!).

First up, I can't seem to convert dvi to ps in Kile. Actually, it doesn't work on the command line either- it says:
dvips: ! Couldn't find header file cm-super-t1.enc.
Note that an absolute path or a relative path with .. are denied in -R2 mode.

R2 is some sort of secure mode. I am using texlive. Part of the problem is that dvips is correct- I really didn't have this file. I installed the following package:

texlive-texmf-cmsuper

But dvips still couldn't see it where it was hiding (which was in /usr/share/texmf-texlive/fonts/enc/dvips/cm-super). It seems that dvips uses the same search-y doo-dah as TeX, so all I needed to do was update the lists by running

texhash

as a superuser. It's happy now.

Thursday, 15 May 2008

Povray

Povray is amazing. This post is really just to remind myself of how to render an image with anti-aliasing from the command line:
povray myimage.pov -geometry 640x480 +A0.1
Hoorah!

Wednesday, 12 March 2008

Another Fortran idiosyncracy bites me on the bum

I thought I'd have this program done by the end of the afternoon. So I start to write a function to calculate a nice simple Gaussian function. No NaNs and +Infs to contend with here, I thought. How wrong I was.
This time, I was finding that the intrinsic function exp(x) returned zero for x less than around -0.1E3. After some bashing, my compiler was sweet enough to tell me:
Result of EXP underflows its kind
Apparently, Fortran is not content with just "exp". It also has "dexp" and "cexp" for double-precision and complex floating point numbers respectively. So, dexp(x) it is then. But be careful how you define x, or you will get a shouty like this:
Type of argument 'x' in call to 'dexp' at (1) should be REAL(8), not REAL(4)
So one should try dexp(-0.1D3) (note the letter D!) rather than exp(-0.1E3), which will return zero, possibly grumbling in the process.

Monday, 10 March 2008

NaN, +Inf, -Inf, horrid things...

This is the answer.
Based on such, I have a sample function to detect a +Inf:

function ispinf(x)
! function to detect if x is +Inf
integer :: ispinf
double precision :: x

!local variables
integer :: IPInf
real :: PInf
data IPInf/B'01111111100000000000000000000000'/ ! +Infinity
PInf = transfer(IPinf,Pinf)

if (x.eq.PInf) then
ispinf = 1
else
ispinf = 0
endif

end function ispinf