L'exemple ci-dessous envoit dix courbes dans un fichier et comprime ce dernier en même temps avec gzip. On utilise le PIPE UNIX.
#ifndef lint
static char sccsid[] = "%W% %G% P. Brochard";
#endif
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include "narcisse.h"
/* ====> M A I N <==== */
int main(int argc,char** argv)
{
/* exemple de trace de courbes + configuration pour Narcisse */
#define nc 10
#define nt 1000
float x[nt];
float y[nt];
int nx[nc];
unsigned i = 0,j = 0,k = 0;
unsigned pas = 2*nt/nc/(nc+1);
SPXFILE* spx_file = NULL;
/* declarations et init tableau de configuration */
SpxArg spx_arg[10];
unsigned n = 0;
SpxInitArg(spx_arg,10);
/* on remplit le tableau de configuration */
SpxSetArgInt(&spx_arg[n],"option_3d",127);n++;
SpxSetArgInt(&spx_arg[n],"calcul_socket",0);n++;
SpxSetArgReel(&spx_arg[n],"courbe_label_x_min",0.91);n++;
SpxSetArgChar(&spx_arg[n],"titre_valeur_gauche","yyy");n++;
SpxSetArgTabInt(&spx_arg[n],"texte_couleur",6,2);
SpxSetArgTabInt(&spx_arg[n],"texte_couleur",3,0);
SpxSetArgTabInt(&spx_arg[n],"texte_couleur",34,3);n++;
SpxSetArgTabReel(&spx_arg[n],"texte_pos_x",0.01,2);n++;
SpxSetArgTabChar(&spx_arg[n],"texte_valeur","essai texte",5);
SpxSetArgTabChar(&spx_arg[n],"texte_valeur","essai texte2",2);
n++;
/* on ouvre un fichier (ici pipe) */
spx_file = SpxOpen("| gzip > toto.spx.gz");
/* on envoit la configuration (qui sera sauvegardee sur
toto.spxrc) */
SpxSetValues(spx_file,spx_arg,n);
/* on nettoie le tableau de configuration */
SpxPurgeArg(spx_arg,10);
/* on genere nc courbes */
for(i=0;i<nc;i++)
{
nx[i] = pas*i + pas;
}
for(i=0,k=0;i<nc;i++)
{
for(j=0;j<nx[i];j++,k++)
{
x[k] = j*j + 100 * i;
y[k] = j;
}
}
/* on envoit toutes les courbes dans le fichier ouvert */
/* (ici socket) */
SpxMulCourbe(x,y,nx,nc,spx_file);
/* on ferme le fichier */
SpxClose(spx_file);
return 0;
}