next up previous contents
Next: LEÇON freefem et gnuplot Up: LEÇON: Introduction au calcul Previous: Programmation

Les Exercices de la leçon


exer574


exer576


remarque572
Pour obtenir une copie de ces fichiers vous pouvez, soit copier coller à partir du "browser" (Netscape...) soit ramener le fichier latex "infosci.tex" dans le même sous répertoire public-html de pironnea.

# fichier makefile pour gcc

.SUFFIXES:	 .cpp
# make variables
export CXX 	= g++
export CXXFLAGS	 = -g 
export CXXINC	= -I/usr/X11/include
export CXXLIBS	= -L/usr/X11/lib -lX11 -lm 
### sources
OBJS =  heatbeam.o rgrafpor.o
heat      :$(OBJS)
	$(CXX)  -o $@ $(OBJS) $(CXXLIBS)
.cpp.o:
	$(CXX) $(CXXFLAGS) $(CXXINC) -c $<
.PHONY:	clean 
###$
clean: 
	rm -f  *.o *~ varia core 
### dependencies
rgrafpor.o: rgrafpor.h
heatbeam.o:rgrafpor.h
### end makefile

// fichier rgrafpor.h
//=====================
void initgraphique();
void closegraphique();
void rattente(int waitm);
void move2(int x, int y);
void line2(int x, int y);
void reffecran();

// fichier rgrafpor.cpp
//========================
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include "rgrafpor.h"

static  Display *display;
static  Window win;
static  XSizeHints size_hints;
static  GC gc;
static  XFontStruct *font_info;
static int screen, width, height, currx, curry;

void closegraphique()
{
  XUnloadFont(display, font_info->fid);
  XFreeGC(display, gc);
  XCloseDisplay(display);
}

void rattente(int waitm)
{
  char click[] = "Click to continue...";
  char values[256];
  XEvent report;

  if (waitm)
    {
      XDrawString (display,
                   win,
                   gc,
                   5,20,
                   click,
                   strlen(click));
      do XNextEvent(display, &report);
      while (report.type != ButtonPress && report.type != KeyPress);
    }
  XCheckMaskEvent(display, ButtonPressMask,&report);
  if (report.type == ButtonPress)
  XFlush (display);
}

int xerror()
{
  fprintf(stderr, "Probleme avec X-Windows\n");
  return 1;
}

void initgraphique()
{
  XEvent report;
  display = XOpenDisplay(NULL);
  font_info = XLoadQueryFont(display, "7x13");
  XSetErrorHandler((XErrorHandler)xerror);
  XSetIOErrorHandler((XIOErrorHandler)xerror);
  screen = DefaultScreen(display);
  width = DisplayWidth(display, screen) - 100;
  height = DisplayHeight(display, screen) - 160;
  win = XCreateSimpleWindow(display, RootWindow(display, screen), 
        50, 80, width, height, 4, BlackPixel(display, screen), 
        WhitePixel(display, screen));

  size_hints.flags = PPosition | PSize;
  size_hints.x = 0;
  size_hints.y = 0;
  size_hints.width = width;
  size_hints.height = height;

  XSetStandardProperties(display, win, "plot", NULL, 0, NULL, 0, &size_hints);
  XSelectInput(display, win, ExposureMask | ButtonPressMask);
  gc = XCreateGC(display, win, 0, NULL);
  XSetFont(display, gc, font_info->fid);
  XSetForeground(display, gc, BlackPixel(display, screen)); 
  XMapWindow(display, win);
  do XNextEvent(display, &report); while (report.type != Expose);
}

void move2(int x, int y)
{
  currx = x;
  curry = y;
}

void line2(int x, int y)
{
  int newx = x, newy = y;
  XDrawLine(display, win, gc, currx, curry, newx, newy);
  currx = newx;
  curry = newy;
}

void reffecran()
{
 XClearWindow(display,win);
}


remarque572
Voici un makefile pour le compilateur xlC de IBM qui suppose qu'on rebatise les fichiers .cpp en .C.

heat: heat.o rgrafpor.o
	xlC -o heat heat.o rgrafpor.o -lX11 -lm

rgrafpor.o:	rgrafpor.C rgrafpor.h
	xlC -c rgrafpor.C

heat.o:	heat.C heat.h rgrafpor.h
	xlC -c heat.C



Pironneau Olivier
Jeudi 12 mars 1998 16:24:39