This page is not yet complete

Some tips ..

This is a collection of some tips that I found out after long hours of Internet search and experimentations. I publish these here for my own reference and in the hope that it helps others to spend less time if they have to face the same problems.



Latex, pstricks, ..

Stand alone eps and pdf figure with pstricks

Fortran

Read data from an input file

Reading input values for a fortran program is not always straightforward. In particular if the data file has some standard and user friendly structure.

Assume that we write a program to compute the roots of second degree polynomial. The input parameters for that program are the three coefficient of the polynomial, and these may be provided to the program in various ways. My preferred solution is to store these values in a text file, where each line has the structure
	parameter name = value
The program accesses then this file to extract the required values. The steps to do so require that we put each line in a string, then identify the parameter name and proceed for the correct value storing for the convenient variable.

For this problem we need to solve the equation of the form
 a x**2 + b*x + c = 0.
The text file may have the following structure:
 # parameter values
 a = 10
 b = -2.3
 c = 1 
The first line being a comment, and the other ones giving the parameter values.
The commented code implements the process of reading the parameter values and doing the usual computations.
 1       PROGRAM POLY2
 2       REAL*8 A,B,C
 3       REAL*8 DELTA,SOL1,SOL2
 4 C SOME VARIABLES ARE NEEDED TO PROCESS THE DATA FILE
 5       INTEGER  N  
 6       CHARACTER*20 FILENAME 
 7       CHARACTER*10 LINE
 8       CHARACTER*3 VARNAME
 9       REAL*8 VARVALUE
10 
11 C READ THE FILE WHERE THE INPUT DATA IS AVAILABLE
12 C (MAKE SURE THE FILE EXISTS)
13       FILENAME='data.txt'
14 
15 C STEP 1 : THE PARAMETER VALUES FROM FILE "DATA.TXT"
16 C IMPORTANT : THERE IS NO DEBUGGING HERE, SO ANY ERROR
17 C MAY LEAD TO UNEXPECTED OUTPUT OR ERROR
18       OPEN(UNIT=1,FILE=FILENAME)
19 
20 1     READ(1,'(a10)',END=3) LINE
21       N=SCAN(LINE,'#',.FALSE.)
22       IF(N.GT.0) GOTO 1
23       N=SCAN(LINE,'=',.FALSE.)
24       IF(N.EQ.0) GOTO 1
25       READ(LINE(1:N-1),'(A5)') VARNAME
26       READ(LINE(N+1:40),*) VARVALUE
27 
28       IF(VARNAME.EQ.'a') THEN
29         A=VARVALUE
30       ELSEIF(VARNAME.EQ.'b') THEN
31         B=VARVALUE
32       ELSEIF(VARNAME.EQ.'c') THEN
33         C=VARVALUE
34         GOTO 3
35       ENDIF
36       GOTO 1
37 3     CONTINUE
38       CLOSE(1)
39 C NOTICE THAT A BETTER STRUCTURE THAN THESE 
40 C MULTIPLE "GOTO" INSTRUCTIONS MAY BE USED
41 
42       PRINT'(A2,F6.3)',"a=",A 
43       PRINT'(A2,F6.3)',"b=",B 
44       PRINT'(A2,F6.3)',"c=",C 
45 
46 
47 C STEP 2 : COMPUTE DELTA AND THE SOLUTION IF THEY EXIST
48       DELTA=B**2.D0-4.D0*A*C
49       IF(DELTA.LT.0.D0) GOTO 10
50       GOTO 100
51 10    CONTINUE
52       PRINT*, "--------------------"
53       PRINT*, "NO REAL SOLUTION"
54       PRINT*, "--------------------"
55       GOTO 1000
56 
57 100   CONTINUE
58       SOL1=(-B-DSQRT(DELTA))/(2.D0*A)
59       SOL2=(-B+DSQRT(DELTA))/(2.D0*A) 
60       PRINT*, "--------------------"
61       PRINT'(A13,F10.5)', "SOLUTION 1 ->",SOL1
62       PRINT'(A13,F10.5)', "SOLUTION 2 ->",SOL2
63       PRINT*, "--------------------"
64       GOTO 1000
65 
66 1000  END

A first graphics with plplot

plplot is a very nice plotting library that can be called from fortran, c, c++, among many other programming languages. This is an example on how to produce a simple figure with fortran.

An illustration through Verhulst dynamics The following code genrates this plot.
 1       program simpleplplot
 2         use plplot
 3       integer n           ! number of points
 4       parameter(n=90)
 5       real*8 x(0:n),y(0:n)    ! table to store values of y
 6       real*8 r            ! value of the parameter r
 7 
 8 c     next define the variable needed for the graphic
 9       real*8 xmin,xmax,ymin,ymax   ! bounding box of the frame
10       character(30) xlab,ylab,title ! labels
11 
12 c     The purpose is to plot the values related by the relation
13 c         y(i) = r * y(i-1) [1 - y(i-1)],
14 c     with parameter value r between 0 and 4, and a starting
15 c     value y(0) between 0 and 1.
16 
17 c     The first Step is to ask the user for the values
18 c     of r and y(0), and then compute y(1) to y(n).
19 c     print*, "The value of the parameter r (0<r<4):"
20 c     read*, r
21 c     print*, "The initial value of y (between 0 and 1):"
22 c     read*, y(1)
23       r=3.9d0
24 
25 
26       x(0)=0.d0
27       y(0)=0.3d0
28       do 100 i=1,n      ! compute the values of y
29          y(i)=r*y(i-1)*(1.d0-y(i-1))
30          x(i)=dble(i)
31 100   continue
32 
33 
34 C     The second step is plot y(i), i=0,..,n.  
35       xmin=0.d0      ! define the size frame
36       xmax=dble(n)
37       ymin=0.d0
38       ymax=1.d0
39       xlab="x"       ! define the labels on the frame
40       ylab="y"
41       title="The emergence of chaos"
42       call plinit()                ! initiate the plot
43       call plcol0(1)               ! chosse color for the frame
44       call plenv(xmin,xmax,ymin,ymax,0,1) ! draw the frame
45       call plcol0(2)               ! choose a color for the labels
46       call pllab(xlab,ylab,title)  ! print the labels
47       call plcol0(3)               ! choose a color for the main curve
48       call plline(x,y)           ! draw the curve
49       call plcol0(2)               ! choose a color for the points
50       call plpoin(x(30:60),y(30:60),21)        ! draw the points
51       call plend()                 ! close the plot environement
52 
53       end
At the compilation, do not forget to link the code to plplot library:
$ gfortran file.f `pkg-config --cflags --libs plplotd-f95`

Mathematica

vim plugins

Awesome WM

With awesome window manager, some programs that use Java do display only a gray windows. This can be fixed by telling Java you use a different window manager by issuing the command line:
$ wmname LG3D 
The utility "sucless-tools" should be installed first. Restart the program after the command. More information on this problem in the following link