[clean-list] Linking Clean to DISLIN

Siegfried Gonzi siegfried.gonzi@stud.uni-graz.at
Sun, 04 May 2003 08:40:04 +0200


I am really surprised how far I got yesterday. I found a way how to
create and link the shared DISLIN library in advance:

- gcc -fIPC -c dis_c.c
- gcc -shared -o libmy.so dis_c.o -L/usr/local/dislinc -lm
- clm libmy.so dis_main

I use it in dis_main: import libmy

I could even made my first quickplot yesterday.

To circumvent the following:

qplot(float *ray,float *yray,int n);

I did:

I use my_malloc and store_double_in_float_p:

void *my_malloc(int size_in_bytes)
{
	return malloc (size_in_bytes);
}

the trick and cheating then is to pass a created 4*n byte my_malloc to a
C-function which expects otherwise a float-pointer (4 bytes):

float *store_double_in_float_p(float *p,int offset,double value)
{
	p[offset]=(float)value;
		return p;
}

/BUT/ in dis.h I specify:

double *store_double_in_float(int *p,int offset,double value);

This is akward though. I did it with "search replace" for every of the
570 DISLIN function. I had also to change short to int; unsigned short
to int;long to int. Otherwise "htoclean dis.h" wouldn't work.

But I haven't found out yet how to pass *char. Do I also have to copy
around things then?

A typical session could be:


==
//curves:: [Real] [Real] -> Int
curves x y
       # n = length x
		//Fill C-floating-point values
       # xf = FillMyMalloc (my_malloc (4*n)) x
       # yf = FillMyMalloc (my_malloc (4*n)) y
		// DISLIN functions starts here
       #! metafl = metafl "eps"
       #! setfil = setfil "/home/gonzi/krishna.eps"
       #! setpag = setpag 2000.0 2000.0
       #! disini = disini
       #! erase = erase
       #! complx = complx
       #! winmod = winmod "NONE"
       #! texmod = texmod "ON"
       #! labdig = labdig 1 "Y"
       #! labdig = labdig 1 "X"
       #! name = name "x" "X"
       #! name = name "y" "Y"
       #! graf = graf 0.0 10.0 0.0 10.0 0.0 10.0 0.0 2.0
       #! xy_plot2 = xy_plot x y
       #! curve = curve x y
       #! endgrf = endgrf
       #! disfin = disfin
       = (disfin,xy_plot2,setfil)


Start = curves [1.0,2.0,3.0,4.0] [1.2,3.4,2.56,2.34]
==

[e.g. texmod "ON" means you could use LaTeX commands for x-y axis
annotation]

This should produce a postscipt output and a quickplot to the screen.
The qickplot on the screen works but not the postscript output.

This is clear because I have no clue how topass from Clean *char to a C
function: how?:

foo(* char); in Clean?: foo("mama mia")?

However, the curious thing actually is I do not get an error message,
which means "setfil=setfil "/home/gonzi/krishna.eps" for example does
not become worked up. I think it has to do with lazy evaluation because
I specify at my exit point only: (disfin,xy_plot2); this means only my
quickplot becomes solved because it does not need disini and disfin (see
postcript). But I think it cannot be the way to list again all the
DISLIN functions at this exit-point?

I am not sure whether the above is safe, because  I have
written 570 wrapper functions in Bigloo: dislin-qplot,...

In Clean it would be possible to write: clean_qplot,... Or is there a
way to specify from which module they come from because writing again
570 wrappers is way to time consuming for me.

Regards,
S. Gonzi
PS: FillMyMalloc for example:
// p has been created with: my_malloc (4*n)
==
FillmyMalloc:: Int [Real] -> Int
FillMyMalloc p ls = store_it p [(x,y)\\y<-ls & x<-[0..]]
where
     store_it::Int [(Int,Real)] -> Int
     store_it p [] = p
     store_it  p [(x,y):t] = store_it (store_double_in_float_p p x y) t
==
==
xy_plot:: [Real] [Real] -> Int
xy_plot x y
	# n = length x
	# xf = FillMyMalloc (my_malloc (4*n)) x
	# yf = FillMyMalloc (my_malloc (4*n)) y
	  //DISLIN function
	= qplot xf yf n
==