    #include <stdio.h>
    #include <stdlib.h>
    #include <errno.h>
    #include <time.h>
    #include <sys/types.h>
    #include <sys/ipc.h>
    #include <sys/msg.h>
    #include "compass.h"

    int main(void)
    {
        struct compass_msgbuf buf;
        int msqid;
        key_t key;
	struct timeval now;	
	suseconds_t time_delta;	

	time_delta = 100000;

	buf.mtype = COMPASS_MSGTYPE;        

        if ((key = ftok("compute.c", 'A')) == -1) {
            perror("ftok");
            exit(1);
        }
	key = 1;
        if ((msqid = msgget(key, 0644 | IPC_CREAT)) == -1) {
            perror("msgget");
            exit(1);
        }

	buf.heading = 0.0;
	buf.mag[0] = 0.0;
	buf.mag[1] = 0.0;
	buf.mag[2] = 0.0;
        gettimeofday(&now,NULL);
	buf.time_sec = now.tv_sec;
	buf.time_usec = now.tv_usec;
        while((msgsnd(msqid, (struct msgbuf *)&buf, sizeof(buf), 0) != -1))
	{
	usleep(time_delta);
	buf.heading = drand48()*360;
	buf.mag[0] = drand48();
	buf.mag[1] = drand48();
	buf.mag[2] = drand48();
        gettimeofday(&now,NULL);
	buf.time_sec = now.tv_sec;
	buf.time_usec = now.tv_usec;
	}		
        perror("msgsnd");

        if (msgctl(msqid, IPC_RMID, NULL) == -1) {
            perror("msgctl");
            exit(1);
        }

        return 0;
    }
