/* In this example, the plot is saved as an xfig file first.
   Next xfig program is invoked. The plot can then be edited using xfig in Unix */
#include <math.h>
#include <chplot.h>

int main() {
    double x[20], y[30], z[600];
    int i,j;
    class CPlot plot;
    linspace(x, -3, 3);
    linspace(y, -4, 4);
    for(i=0; i<20; i++) {
        for(j=0; j<30; j++) {
            z[30*i+j] = 3*(1-x[i])*(1-x[i])*exp(-(x[i]*x[i])-(y[j]+1)*(y[j]+1))
            - 10*(x[i]/5 - x[i]*x[i]*x[i]-pow(y[j],5))*exp(-x[i]*x[i]-y[j]*y[j])
            - 1/3*exp(-(x[i]+1)*(x[i]+1)-y[j]*y[j]);
    plot.data3D(x, y, z);
    plot.outputType(PLOT_OUTPUTTYPE_FILE, "fig", "../output/outputType_2.fig");

    xfig ../output/outputType_2.fig&