import visad.*;
import visad.java3d.DisplayImplJ3D;
import visad.java2d.DisplayImplJ2D;
import java.rmi.RemoteException;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

class f1 extends f_xj
{
public double func(double x[]) 
{
//çözümü istenen fonksiyon	
double ff;
ff=(x[1]-x[0]*x[0])*(x[1]-x[0]*x[0])+0.01*(x[0]-1.0)*(x[0]-1.0);
return -ff; 
}
}

public class Plot3D{
   
   public static double[] grid(f_xj f,double x1min,double x1max,double x2min,double x2max,int NCOLS,int NROWS)
   {  //create 1D Z grid for Z value from a given function value         
	float[][] zi = new float[2][NCOLS * NROWS];
    float xx[][]=new float[2][NCOLS * NROWS];
    double zz[]=new double[NCOLS * NROWS];
    double x[]=new double[2];
    for(int c = 0; c < NCOLS; c++)
      for(int r = 0; r < NROWS; r++)
      { xx[0][ c * NROWS + r ]=(float)(x1min+(x1max-x1min)*c/(float)(NCOLS-1));
        x[0]=(x1min+(x1max-x1min)*c/(float)(NCOLS-1));
        xx[1][ c * NROWS + r ]=(float)(x2min+(x2max-x2min)/(float)(NROWS-1)*r);
        x[1]=(x2min+(x2max-x2min)*r/(float)(NROWS-1));
        zz[ c * NROWS + r ]=f.func(x);
      }               
    return zz;
   }
   
   public static double[][] grid2D(f_xj f,double x1min,double x1max,double x2min,double x2max,int NCOLS,int NROWS)
   {  //create 2D Z grid for Z value from a given function value   
	
   float[][] zi = new float[2][NCOLS * NROWS];
    float xx[][]=new float[2][NCOLS * NROWS];
    double zz[][]=new double[NCOLS][NROWS];
    double x[]=new double[2];
       for(int c = 0; c < NCOLS; c++) 
           for(int r = 0; r < NROWS; r++)
      { xx[0][ c * NROWS + r ]=(float)(x1min+(x1max-x1min)*c/(float)(NCOLS-1));
        x[0]=(x1min+(x1max-x1min)*c/(float)(NCOLS-1));
        xx[1][ c * NROWS + r ]=(float)(x2min+(x2max-x2min)/(float)(NROWS-1)*r);
        x[1]=(x2min+(x2max-x2min)*r/(float)(NROWS-1));
        zz[c][r]=f.func(x);
      }               
    return zz;
   }
   
   public static void plot3D_CD2(double zz[][],double x1min,double x1max,double x2min,double x2max,int NCONTOUR,String sx,String sy,String sz) throws RemoteException, VisADException	    
   {
   RealType longitude, latitude;
   RealType altitude;
  // Tuple to pack longitude and latitude together
   RealTupleType domain_tuple;
  // The function (domain_tuple -> altitude )
   FunctionType func_domain_alt;
   // Our Data values for the domain are represented by the Set
   Set domain_set;
  // The Data class FlatField
   FlatField vals_ff;
  // The DataReference from data to display
   DataReferenceImpl data_ref;
  // The 2D display, and its the maps
   DisplayImpl display;
   ScalarMap latMap, lonMap;
   ScalarMap altMap, altRGBMap;
   ScalarMap altAlphaMap;

   ColorControl colCont;

  // Our color table

   float[][] myColorTable;

    // Create the quantities
    // Use RealType(String name, Unit unit, Set set);

    latitude = RealType.getRealType(sx, SI.meter, null);
    longitude = RealType.getRealType(sy, SI.meter, null);
    altitude = RealType.getRealType("z", SI.meter, null);
    domain_tuple = new RealTupleType(latitude, longitude);

    

    // Create a FunctionType (domain_tuple -> range_tuple )
    // Use FunctionType(MathType domain, MathType range)

    func_domain_alt = new FunctionType( domain_tuple, altitude);

    // Create the domain Set, with 12 columns and 6 rows, using an
    // LinearDSet(MathType type, double first1, double last1, int lengthX,
    //				 double first2, double last2, int lengthY)

    // note the "inverted" first and last values of latitude

    int NCOLS = zz[0].length;;
    int NROWS = zz.length;

    domain_set = new Linear2DSet(domain_tuple, x1min, x1max, NROWS,
    					          x2min, x2max, NCOLS);



    // The actal altitudes values
    // ordered as float[ NROWS ][ NCOLS ]

    double[][] alt_samples = zz;


    // Our 'flat' array

    double[][] flat_samples = new double[1][NCOLS * NROWS];

    // Fill our 'flat' array with the altitude values
    // by looping over NCOLS and NROWS

    // Note the use of an index variable, indicating the order of the samples

    int index = 0;
    double zmin=2.0e60,zmax=-2e60;;
    for(int c = 0; c < NCOLS; c++)
      for(int r = 0; r < NROWS; r++)
      {
	      flat_samples[0][ index ] = alt_samples[c][r];
	      if(flat_samples[0][ index ]<zmin) zmin=flat_samples[0][ index ];
	      if(flat_samples[0][ index ]>zmax) zmax=flat_samples[0][ index ];
	      index++;
      }
    // Create a FlatField
    // Use FlatField(FunctionType type, Set domain_set)

    vals_ff = new FlatField( func_domain_alt, domain_set);



    // ...and put the altitude values above into it

    // Note the argument false, meaning that the array won't be copied

    vals_ff.setSamples( flat_samples , false );


    // Create Display and its maps

    display = new DisplayImplJ3D("display1");

    // Get display's graphics mode control and draw scales

    GraphicsModeControl dispGMC = (GraphicsModeControl)  display.getGraphicsModeControl();
    dispGMC.setScaleEnable(true);

    // Also enable Texture
    //dispGMC.setTextureEnable(false);
    dispGMC.setTextureEnable(true);

    // Create the ScalarMaps: latitude to XAxis, longitude to YAxis and
    // altitude to ZAxis and to RGB
    // Use ScalarMap(ScalarType scalar, DisplayRealType display_scalar)

    latMap = new ScalarMap( latitude,    Display.XAxis );
    lonMap = new ScalarMap( longitude, Display.YAxis );


    altRGBMap = new ScalarMap( altitude,  Display.RGB );

    altMap = new ScalarMap( altitude,  Display.ZAxis );

    altAlphaMap = new ScalarMap( altitude,  Display.Alpha );

    // Add maps to display

    display.addMap( latMap );
    display.addMap( lonMap );

    display.addMap( altMap );
    display.addMap( altRGBMap );
    display.addMap( altAlphaMap );

    // Create a different color table
    // Note: table has red, green and blue components
    // and is 10 units long, i.e float[3][10]


    int tableLength = 10;

    myColorTable = new float[3][tableLength];

    for(int i=0;i<tableLength;i++){

      myColorTable[0][i]= (float) 1.0f - (float)i / ((float)tableLength-1.0f); // red component
      myColorTable[1][i]= (float) (float)i / ((float)tableLength-1.0f); // green component
      myColorTable[2][i]= (float) 0.50f; // blue component

    }

    // Force top of table to be white
    myColorTable[0][9]=1.0f;
    myColorTable[1][9]=1.0f;
    myColorTable[2][9]=1.0f;

    // Get the ColorControl from the altitude RGB map

    colCont = (ColorControl) altRGBMap.getControl();

    // Set the table

    colCont.setTable(myColorTable );


    // Create a data reference and set the FlatField as our data

    data_ref = new DataReferenceImpl("data_ref");
    data_ref.setData( vals_ff );


    display.addReference( data_ref);

    // Set maps ranges
    latMap.setRange(x1min, x1max);
    altMap.setRange(zmin, zmax);


    // Create application window and add display to window

    JFrame jframe = new JFrame("Plot3D");
    jframe.getContentPane().add(display.getComponent());

    // Add the LabeledColorWidget to the frame


    // Set window size and make it visible

    jframe.setSize(300, 300);
    jframe.setVisible(true);
   }
   
   public static void plot3D_CD1(f_xj f,double x1min,double x1max,double x2min,double x2max,int NCOLS,int NROWS,int NCONTOUR,String sx,String sy,String sz) throws RemoteException, VisADException
   { plot3D_CD1(grid2D(f,x1min,x1max,x2min,x2max,NCOLS, NROWS),x1min,x1max,x2min,x2max,NCONTOUR,sx,sy,sz);}
   	    
   public static void plot3D_CD1(double zz[][],double x1min,double x1max,double x2min,double x2max,int NCONTOUR,String sx,String sy,String sz) throws RemoteException, VisADException	    
   {
    RealType longitude, latitude;
    RealType altitude;

   // Tuple to pack longitude and latitude together

    RealTupleType domain_tuple;


  // The function (domain_tuple -> altitude )

   FunctionType func_domain_alt;


   // Our Data values for the domain are represented by the Set

   Set domain_set;


  // The Data class FlatField

   FlatField vals_ff;

  // The DataReference from data to display

   DataReferenceImpl data_ref;

  // The 2D display, and its the maps

   DisplayImpl display;
   ScalarMap latMap, lonMap;
   ScalarMap altMap, altRGBMap;

   ColorControl colCont;

  // Our color table

   float[][] myColorTable;

    // Create the quantities
    // Use RealType(String name, Unit unit, Set set);

    latitude = RealType.getRealType(sx, SI.meter);
    longitude = RealType.getRealType(sy, SI.meter);
    altitude  = RealType.getRealType("z", SI.meter);
    domain_tuple = new RealTupleType(latitude, longitude);
    //String ss=sz;
    //altitude = RealType.getRealType("z", SI.meter);


    // Create a FunctionType (domain_tuple -> range_tuple )
    // Use FunctionType(MathType domain, MathType range)

    func_domain_alt = new FunctionType( domain_tuple, altitude);

    // Create the domain Set, with 12 columns and 6 rows, using an
    // LinearDSet(MathType type, double first1, double last1, int lengthX,
    //				 double first2, double last2, int lengthY)

    // note the "inverted" first and last values of latitude

    int NCOLS = zz.length;
    int NROWS = zz[0].length;

    domain_set = new Linear2DSet(domain_tuple, x1min,x1max, NROWS,
    					          x2min, x2max, NCOLS);

    // The actal altitudes values
    // ordered as float[ NROWS ][ NCOLS ]

    double[][] alt_samples = zz;
    double[][] flat_samples = new double[1][NCOLS * NROWS];

    int index = 0;
    double zmin=2.0e60,zmax=-2e60;;
    for(int c = 0; c < NCOLS; c++)
      for(int r = 0; r < NROWS; r++)
      {
	      flat_samples[0][ index ] = alt_samples[c][r];
	      if(flat_samples[0][ index ]<zmin) zmin=flat_samples[0][ index ];
	      if(flat_samples[0][ index ]>zmax) zmax=flat_samples[0][ index ];
	      index++;
      }
    // Create a FlatField
    // Use FlatField(FunctionType type, Set domain_set)
    vals_ff = new FlatField( func_domain_alt, domain_set);
    FlatField der_vals_ff ;//= new FlatField( func_domain_alt, domain_set);
    // ...and put the altitude values above into it
    // Note the argument false, meaning that the array won't be copied
    vals_ff.setSamples( flat_samples , false );
    der_vals_ff = (FlatField) vals_ff.derivative( longitude, Data.NO_ERRORS );//.setSamples( flat_samples , false );
    // Create Display and its maps
    display = new DisplayImplJ3D("display1");
    // Get display's graphics mode control and draw scales
    GraphicsModeControl dispGMC = (GraphicsModeControl)  display.getGraphicsModeControl();
    dispGMC.setScaleEnable(true);
    // Also enable Texture
    dispGMC.setTextureEnable(false);
    // Create the ScalarMaps: latitude to XAxis, longitude to YAxis and
    // altitude to ZAxis and to RGB
    // Use ScalarMap(ScalarType scalar, DisplayRealType display_scalar)
    latMap = new ScalarMap( latitude,    Display.XAxis );
    lonMap = new ScalarMap( longitude, Display.YAxis );


    altRGBMap = new ScalarMap( altitude,  Display.RGB );

    altMap = new ScalarMap( altitude,  Display.ZAxis );

    // Add maps to display

    display.addMap( latMap );
    display.addMap( lonMap );

    display.addMap( altMap );
    display.addMap( altRGBMap );

    // Create a color table
    // Note: table has red, green and blue components
    // and is 8 units long, i.e float[3][8]

    myColorTable = new float[][]{{0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f},  // red component
                                 {0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f},  // green component
                                 {0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f}}; // blue component

    // Get the ColorControl from the altitude RGB map
    colCont = (ColorControl) altRGBMap.getControl();
    // Set the table
    colCont.setTable(myColorTable );
    // Create a data reference and set the FlatField as our data
    data_ref = new DataReferenceImpl("data_ref");
    data_ref.setData( vals_ff );


    display.addReference( data_ref);

    // Set maps ranges
    latMap.setRange(x1min, x1max);
    lonMap.setRange(x2min, x2max);
    altMap.setRange(zmin, zmax);


    // Create application window and add display to window

    JFrame jframe = new JFrame(sz);
    jframe.getContentPane().add(display.getComponent());

    // Add the LabeledColorWidget to the frame


    // Set window size and make it visible

    jframe.setSize(300, 300);
    jframe.setVisible(true);
   }
   
   public static void plot3D_CD(f_xj f,double x1min,double x1max,double x2min,double x2max,int NCOLS,int NROWS,int NCONTOUR,String sx,String sy,String sz) throws RemoteException, VisADException
   { plot3D_CD(grid2D(f,x1min,x1max,x2min,x2max,NCOLS, NROWS),x1min,x1max,x2min,x2max,NCONTOUR,sx,sy,sz);}
   	    
   
   public static void plot3D_CD(double zz[][],double x1min,double x1max,double x2min,double x2max,int NCONTOUR,String sx,String sy,String sz) throws RemoteException, VisADException	    
   { 
   //===============
   // Declare variables
   // The domain quantities longitude and latitude
   // and the dependent quantity altitude
   RealType longitude, latitude;
   RealType altitude;

  // Tuple to pack longitude and latitude together

   RealTupleType domain_tuple;


  // The function (domain_tuple -> altitude )

   FunctionType func_domain_alt;


   // Our Data values for the domain are represented by the Set

   Set domain_set;


  // The Data class FlatField

   FlatField vals_ff;

  // The DataReference from data to display

   DataReferenceImpl data_ref;

  // The 2D display, and its the maps

   DisplayImpl display;
   ScalarMap latMap, lonMap;
   ScalarMap altMap, altRGBMap;

   ColorControl colCont;

  // Our color table

   float[][] myColorTable;


    // Create the quantities
    // Use RealType(String name, Unit unit, Set set);

    latitude = RealType.getRealType(sx, SI.meter, null);
    longitude = RealType.getRealType(sy, SI.meter, null);

    domain_tuple = new RealTupleType(latitude, longitude);

    altitude = RealType.getRealType("z", SI.meter, null);

    // Create a FunctionType (domain_tuple -> range_tuple )
    // Use FunctionType(MathType domain, MathType range)

    func_domain_alt = new FunctionType( domain_tuple, altitude);

    // Create the domain Set, with 12 columns and 6 rows, using an
    // LinearDSet(MathType type, double first1, double last1, int lengthX,
    //				 double first2, double last2, int lengthY)

    // note the "inverted" first and last values of latitude
    // The actal altitudes values
    // ordered as float[ NROWS ][ NCOLS ]

     double[][] alt_samples =zz; 

     int NROWS=alt_samples.length;
     int NCOLS=alt_samples[0].length;	
      domain_set = new Linear2DSet(domain_tuple, x1min,x1max, NROWS,
    					          x2min,  x2max, NCOLS);
    // Our 'flat' array

    double[][] flat_samples = new double[1][NCOLS * NROWS];

    // Fill our 'flat' array with the altitude values
    // by looping over NCOLS and NROWS

    // Note the use of an index variable, indicating the order of the samples

    int index = 0;

    for(int c = 0; c < NCOLS; c++)

      for(int r = 0; r < NROWS; r++){

	  // set altitude altitude
	  flat_samples[0][ index ] = alt_samples[r][c];

	  // increment index
	  index++;
      }

    // Create a FlatField
    // Use FlatField(FunctionType type, Set domain_set)

    vals_ff = new FlatField( func_domain_alt, domain_set);

    // ...and put the altitude values above into it
    // Note the argument false, meaning that the array won't be copied

    vals_ff.setSamples( flat_samples , false );


    // Code for slope data

      // Data in a FlatField

      FlatField slope_vals_ff ;

      // Calculate derivative of altitude with respect to longitude; assume no errors

      slope_vals_ff = (FlatField) vals_ff.derivative( longitude, Data.NO_ERRORS );


      // Get the funtionc from the FlatField for slope

      FunctionType func_domain_slope = ((FunctionType)slope_vals_ff.getType());

      // "slope" is a RealType;

      RealType slope = (RealType) func_domain_slope.getRange();


      // Create a ScalarMap to color slope's surface

      ScalarMap slopeRGBMap = new ScalarMap( slope,  Display.RGB );


    // Create Display and its maps


    display = new DisplayImplJ3D("display1");

    // Get display's graphics mode control and draw scales

    GraphicsModeControl dispGMC = (GraphicsModeControl)  display.getGraphicsModeControl();
    dispGMC.setScaleEnable(true);

    // Also enable Texture
    dispGMC.setTextureEnable(false);


    // Create the ScalarMaps: latitude to XAxis, longitude to YAxis and
    // altitude to ZAxis and to RGB
    // Use ScalarMap(ScalarType scalar, DisplayRealType display_scalar)

    latMap = new ScalarMap( latitude,    Display.XAxis );
    lonMap = new ScalarMap( longitude, Display.YAxis );


    altRGBMap = new ScalarMap( altitude,  Display.RGB );


    altMap = new ScalarMap( altitude,  Display.ZAxis );


    // Add maps to display

    display.addMap( latMap );
    display.addMap( lonMap );
    display.addMap( altMap );
    display.addMap( altRGBMap );
    display.addMap( slopeRGBMap );

    // Create a color table
    // Note: table has red, green and blue components
    // and is 8 units long, i.e float[3][8]

    myColorTable = new float[][]{{0, 1, 0, 0, 0, 1, 1, 1},  // red component
     			                       {0, 0, 1, 0, 1, 0, 1, 1},  // green component
     				                     {0, 0, 0, 1, 1, 1, 0, 1}}; // blue component


    // Get the ColorControl from the altitude RGB map

    colCont = (ColorControl) altRGBMap.getControl();

    // Set the table

    colCont.setTable(myColorTable );


    // Create a data reference and set the FlatField as our data

    data_ref = new DataReferenceImpl("data_ref");
    data_ref.setData( vals_ff );

    // Data reference for slope
    DataReferenceImpl data_ref2 = new DataReferenceImpl("data_ref2");
    data_ref2.setData( slope_vals_ff );

     // Add reference to display
    ConstantMap[] constAlpha_CMap = {
        	     new ConstantMap( 0.50f, Display.Alpha)};


    ConstantMap[] constZ_CMap = {
        	     new ConstantMap( -1.0f, Display.ZAxis)};

	// Add references to display
  // order MATTERS!

	 display.addReference( data_ref2, constZ_CMap );
   display.addReference( data_ref, constAlpha_CMap );

    // Set maps ranges
    latMap.setRange(x1min, x1max);
    lonMap.setRange(x2min, x2max);
    //altMap.setRange(zmin, zmax);

    // Create application window and add display to window

    JFrame jframe = new JFrame(sz);
    jframe.getContentPane().add(display.getComponent());

    // Add the LabeledColorWidget to the frame


    // Set window size and make it visible

    jframe.setSize(300, 300);
    jframe.setVisible(true);
    }
   //================
   public static void plot3D_RGB(double zz[][],double x1min,double x1max,double x2min,double x2max,int NCONTOUR,String sx,String sy,String sz) throws RemoteException, VisADException	    
   {
   int NROWS=zz[0].length;
   int NCOLS=zz.length;	   
   RealType x1, x2;
   RealType z, temperature,  precipitation;
  // Two Tuples: one to pack longitude and latitude together, as the domain
  // and the other for the range (altitude, temperature)
   RealTupleType domain_tuple, range_tuple;
  // The function (domain_tuple -> range_tuple )
   FunctionType func_domain_range;
   // Our Data values for the domain are represented by the Set
   Set domain_set;
  // The Data class FlatField
   FlatField vals_ff;
  // The DataReference from data to display
   DataReferenceImpl data_ref;
  // The 2D display, and its the maps
   DisplayImpl display;
   ScalarMap latMap, lonMap;
   ScalarMap altZMap, tempRGBMap;
   ScalarMap tempZMap, altRGBMap;
   ScalarMap tempIsoMap;
    // Create the quantities
    // Use RealType(String name);
    x1 = RealType.getRealType(sx,null,null);
    x2 = RealType.getRealType(sy,null,null);
    domain_tuple = new RealTupleType(x1, x2);
    temperature = RealType.getRealType("temperature",null,null);
    z = RealType.getRealType("z",null,null);
    range_tuple = new RealTupleType( z, temperature  );
    // Create a FunctionType (domain_tuple -> range_tuple )
    // Use FunctionType(MathType domain, MathType range)
    func_domain_range = new FunctionType( domain_tuple, range_tuple);
    // Create the domain Set
    // Use LinearDSet(MathType type, double first1, double last1, int lengthX,
    //				     double first2, double last2, int lengthY)
    domain_set = new Linear2DSet(domain_tuple, x1min, x1max, NROWS,
    					       x2min, x2max, NCOLS);
    // Get the Set samples to facilitate the calculations
    float[][] x_j = domain_set.getSamples( true );
    // We create another array, with the same number of elements of
    // altitude and temperature, but organized as
    // float[2][ number_of_samples ]
    float[][] zi = new float[2][NCOLS*NROWS];
    // ...and then we fill our 'flat' array with the generated values
    // by looping over NCOLS and NROWS
    double xx[]=new double[2];

    for(int c = 0; c < NCOLS; c++)
      for(int r = 0; r < NROWS; r++)
      {xx[0]=(float)(x1min+(x1max-x1min)*c/(float)(NCOLS-1));
       xx[1]=(float)(x2min+(x2max-x2min)*r/(float)(NROWS-1));
       zi[0][ c * NROWS + r ] = (float)zz[c][r];
	   zi[1][ c * NROWS + r ] = (float)xx[1];
    }
    // Create a FlatField
    // Use FlatField(FunctionType type, Set domain_set)
    vals_ff = new FlatField( func_domain_range, domain_set);
    // ...and put the values above into it
    // Note the argument false, meaning that the array won't be copied
    vals_ff.setSamples( zi , false );
    // Create Display and its maps
    // A 2D display
    display = new DisplayImplJ3D(sz);
    // Get display's graphics mode control and draw scales
    GraphicsModeControl dispGMC = (GraphicsModeControl)  display.getGraphicsModeControl();
    dispGMC.setScaleEnable(true);
    // Create the ScalarMaps: latitude to YAxis, longitude to XAxis and
    // altitude to ZAxis and temperature to RGB
    // Use ScalarMap(ScalarType scalar, DisplayRealType display_scalar)
    latMap = new ScalarMap( x1,Display.XAxis );
    lonMap = new ScalarMap( x2,Display.YAxis );
    // Add maps to display
    display.addMap( latMap );
    display.addMap( lonMap );
     // altitude to z-axis and temperature to color
    altZMap = new ScalarMap( z,  Display.ZAxis );
    tempRGBMap = new ScalarMap( temperature,  Display.RGB );
    tempIsoMap = new ScalarMap( temperature,  Display.IsoContour );
    display.addMap( tempRGBMap );
    display.addMap( tempIsoMap );
    // Add maps to display
    display.addMap( altZMap );
    
    // Uncomment following lines to have different data depiction
    // temperature to z-axis and altitude to color
    //altRGBMap = new ScalarMap( zi,  Display.RGB );
    //tempZMap = new ScalarMap( temperature,  Display.ZAxis );
    //display.addMap( altRGBMap );
    //display.addMap( tempZMap );
    // Create a data reference and set the FlatField as our data
    data_ref = new DataReferenceImpl("data_ref");
    data_ref.setData( vals_ff );
    // Add reference to display
    display.addReference( data_ref );
    // Create application window and add display to window
    JFrame jframe = new JFrame(sz);
    jframe.getContentPane().add(display.getComponent());
    // Set window size and make it visible
    jframe.setSize(300, 300);
    jframe.setVisible(true);   
   }   
      
   public static void plot3D_RGB(double zz[],double x1min,double x1max,double x2min,double x2max,int NCOLS,int NROWS,int NCONTOUR,String sx,String sy,String sz) throws RemoteException, VisADException	    
   {
   RealType x1, x2;
   RealType z, temperature,  precipitation;
  // Two Tuples: one to pack longitude and latitude together, as the domain
  // and the other for the range (altitude, temperature)
   RealTupleType domain_tuple, range_tuple;
  // The function (domain_tuple -> range_tuple )
   FunctionType func_domain_range;
   // Our Data values for the domain are represented by the Set
   Set domain_set;
  // The Data class FlatField
   FlatField vals_ff;
  // The DataReference from data to display
   DataReferenceImpl data_ref;
  // The 2D display, and its the maps
   DisplayImpl display;
   ScalarMap latMap, lonMap;
   ScalarMap altZMap, tempRGBMap;
   ScalarMap tempZMap, altRGBMap;
   ScalarMap tempIsoMap;
    // Create the quantities
    // Use RealType(String name);
    x1 = RealType.getRealType(sx,null,null);
    x2 = RealType.getRealType(sy,null,null);
    domain_tuple = new RealTupleType(x1, x2);
    temperature = RealType.getRealType("temperature",null,null);
    z = RealType.getRealType("z",null,null);
    range_tuple = new RealTupleType( z, temperature  );
    // Create a FunctionType (domain_tuple -> range_tuple )
    // Use FunctionType(MathType domain, MathType range)
    func_domain_range = new FunctionType( domain_tuple, range_tuple);
    // Create the domain Set
    // Use LinearDSet(MathType type, double first1, double last1, int lengthX,
    //				     double first2, double last2, int lengthY)
    domain_set = new Linear2DSet(domain_tuple, x1min, x1max, NROWS,
    					       x2min, x2max, NCOLS);
    // Get the Set samples to facilitate the calculations
    float[][] x_j = domain_set.getSamples( true );
    // We create another array, with the same number of elements of
    // altitude and temperature, but organized as
    // float[2][ number_of_samples ]
    float[][] zi = new float[2][NCOLS*NROWS];
    // ...and then we fill our 'flat' array with the generated values
    // by looping over NCOLS and NROWS
    double xx[]=new double[2];

    for(int c = 0; c < NCOLS; c++)
      for(int r = 0; r < NROWS; r++)
      {xx[0]=(float)(x1min+(x1max-x1min)*c/(float)(NCOLS-1));
       xx[1]=(float)(x2min+(x2max-x2min)*r/(float)(NROWS-1));
       zi[0][ c * NROWS + r ] = (float)zz[ c * NROWS + r ];
	   zi[1][ c * NROWS + r ] = (float)xx[1];
    }
    // Create a FlatField
    // Use FlatField(FunctionType type, Set domain_set)
    vals_ff = new FlatField( func_domain_range, domain_set);
    // ...and put the values above into it
    // Note the argument false, meaning that the array won't be copied
    vals_ff.setSamples( zi , false );
    // Create Display and its maps
    // A 2D display
    display = new DisplayImplJ3D(sz);
    // Get display's graphics mode control and draw scales
    GraphicsModeControl dispGMC = (GraphicsModeControl)  display.getGraphicsModeControl();
    dispGMC.setScaleEnable(true);
    // Create the ScalarMaps: latitude to YAxis, longitude to XAxis and
    // altitude to ZAxis and temperature to RGB
    // Use ScalarMap(ScalarType scalar, DisplayRealType display_scalar)
    latMap = new ScalarMap( x1,Display.YAxis );
    lonMap = new ScalarMap( x2,Display.XAxis );
    // Add maps to display
    display.addMap( latMap );
    display.addMap( lonMap );
     // altitude to z-axis and temperature to color
    altZMap = new ScalarMap( z,  Display.ZAxis );
    tempRGBMap = new ScalarMap( temperature,  Display.RGB );
    tempIsoMap = new ScalarMap( temperature,  Display.IsoContour );
    display.addMap( tempRGBMap );
    display.addMap( tempIsoMap );
    // Add maps to display
    display.addMap( altZMap );
    
    // Uncomment following lines to have different data depiction
    // temperature to z-axis and altitude to color
    altRGBMap = new ScalarMap( z,  Display.RGB );
    tempZMap = new ScalarMap( temperature,  Display.ZAxis );
    display.addMap( altRGBMap );
    display.addMap( tempZMap );
    // Create a data reference and set the FlatField as our data
    data_ref = new DataReferenceImpl("data_ref");
    data_ref.setData( vals_ff );
    // Add reference to display
    display.addReference( data_ref );
    // Create application window and add display to window
    JFrame jframe = new JFrame(sz);
    jframe.getContentPane().add(display.getComponent());
    // Set window size and make it visible
    jframe.setSize(300, 300);
    jframe.setVisible(true);
   }
   
   public static void plot3D_RGB(f_xj f,double x1min,double x1max,double x2min,double x2max,int NCOLS,int NROWS,int NCONTOUR,String sx,String sy,String sz) throws RemoteException, VisADException	
   {
   RealType x1, x2;
   RealType z, temperature,  precipitation;
  // Two Tuples: one to pack longitude and latitude together, as the domain
  // and the other for the range (altitude, temperature)
   RealTupleType domain_tuple, range_tuple;
  // The function (domain_tuple -> range_tuple )
   FunctionType func_domain_range;
   // Our Data values for the domain are represented by the Set
   Set domain_set;
  // The Data class FlatField
   FlatField vals_ff;
  // The DataReference from data to display
   DataReferenceImpl data_ref;
  // The 2D display, and its the maps
   DisplayImpl display;
   ScalarMap latMap, lonMap;
   ScalarMap altZMap, tempRGBMap;
   ScalarMap tempZMap, altRGBMap;
   ScalarMap tempIsoMap;
    // Create the quantities
    // Use RealType(String name);
    x1 = RealType.getRealType(sx,null,null);
    x2 = RealType.getRealType(sy,null,null);
    domain_tuple = new RealTupleType(x1, x2);
    temperature = RealType.getRealType("temperature",null,null);
    z = RealType.getRealType("z",null,null);
    range_tuple = new RealTupleType( z, temperature  );
    // Create a FunctionType (domain_tuple -> range_tuple )
    // Use FunctionType(MathType domain, MathType range)
    func_domain_range = new FunctionType( domain_tuple, range_tuple);
    // Create the domain Set
    // Use LinearDSet(MathType type, double first1, double last1, int lengthX,
    //				     double first2, double last2, int lengthY)
    domain_set = new Linear2DSet(domain_tuple, x1min, x1max, NROWS,
    					       x2min, x2max, NCOLS);
    // Get the Set samples to facilitate the calculations
    float[][] x_j = domain_set.getSamples( true );
    // We create another array, with the same number of elements of
    // altitude and temperature, but organized as
    // float[2][ number_of_samples ]
    float[][] zi = new float[2][NCOLS * NROWS];
    // ...and then we fill our 'flat' array with the generated values
    // by looping over NCOLS and NROWS
    double xx[]=new double[2];
    for(int c = 0; c < NCOLS; c++)
      for(int r = 0; r < NROWS; r++)
      {xx[0]=x_j[0][ c * NROWS + r ];
       xx[1]=x_j[1][ c * NROWS + r ];
       zi[0][ c * NROWS + r ] = (float)f.func(xx);
	   zi[1][ c * NROWS + r ] = x_j[1][ c * NROWS + r ];
    }
    // Create a FlatField
    // Use FlatField(FunctionType type, Set domain_set)
    vals_ff = new FlatField( func_domain_range, domain_set);
    // ...and put the values above into it
    // Note the argument false, meaning that the array won't be copied
    vals_ff.setSamples( zi , false );
    // Create Display and its maps
    // A 2D display
    display = new DisplayImplJ3D(sz);
    // Get display's graphics mode control and draw scales
    GraphicsModeControl dispGMC = (GraphicsModeControl)  display.getGraphicsModeControl();
    dispGMC.setScaleEnable(true);
    // Create the ScalarMaps: latitude to YAxis, longitude to XAxis and
    // altitude to ZAxis and temperature to RGB
    // Use ScalarMap(ScalarType scalar, DisplayRealType display_scalar)
    latMap = new ScalarMap( x1,Display.YAxis );
    lonMap = new ScalarMap( x2,Display.XAxis );
    // Add maps to display
    display.addMap( latMap );
    display.addMap( lonMap );
     // altitude to z-axis and temperature to color
    altZMap = new ScalarMap( z,  Display.ZAxis );
    tempRGBMap = new ScalarMap( temperature,  Display.RGB );
    //tempIsoMap = new ScalarMap( temperature,  Display.IsoContour );
    display.addMap( tempRGBMap );
    //display.addMap( tempIsoMap );
    // Add maps to display
    display.addMap( altZMap );
    
    // Uncomment following lines to have different data depiction
    // temperature to z-axis and altitude to color
    //altRGBMap = new ScalarMap( zi,  Display.RGB );
    //tempZMap = new ScalarMap( temperature,  Display.ZAxis );
    //display.addMap( altRGBMap );
    //display.addMap( tempZMap );
    // Create a data reference and set the FlatField as our data
    data_ref = new DataReferenceImpl("data_ref");
    data_ref.setData( vals_ff );
    // Add reference to display
    display.addReference( data_ref );
    // Create application window and add display to window
    JFrame jframe = new JFrame(sz);
    jframe.getContentPane().add(display.getComponent());
    // Set window size and make it visible
    jframe.setSize(400, 400);
    jframe.setVisible(true);
  }
   
public static void contour_Plot1(f_xj f, double x1min,double x1max,double x2min,double x2max,int NROWS,int NCOLS,int NCONTOUR,String s1,String s2,String s3)
    throws RemoteException, VisADException 
    {
	// Declare variables
  // The domain quantities longitude and latitude
  // and the dependent quantity temperature

  RealType longitude, latitude;
  RealType temperature;


  // Tuple to pack longitude and latitude together, as the domain

  RealTupleType domain_tuple;


  // The function (domain_tuple -> temperature )
  // Remeber, range is only "temperature"

  FunctionType func_domain_temp;


   // Our Data values for the domain are represented by the Set

  Set domain_set;


  // The Data class FlatField

  FlatField vals_ff;

  // The DataReference from data to display

  DataReferenceImpl data_ref;

  // The 2D display, and its the maps

  DisplayImpl display;
  ScalarMap latMap, lonMap;
  ScalarMap tempIsoMap, tempRGBMap;

  // These objects are for drawing isocontours

  RealType isoTemperature;
  FunctionType func_domain_isoTemp;

  FlatField iso_vals_ff;
  DataReferenceImpl iso_data_ref;
    // Create the quantities
    // Use RealType(String name);
    latitude = RealType.getRealType(s1);
    longitude = RealType.getRealType(s2);
    domain_tuple = new RealTupleType(latitude, longitude);
    temperature = RealType.getRealType("temperature", SI.kelvin, null);
    isoTemperature = RealType.getRealType("isoTemperature", SI.kelvin, null);
    // Create a FunctionType (domain_tuple -> temperature )
    // Use FunctionType(MathType domain, MathType range)
    func_domain_temp = new FunctionType( domain_tuple, temperature);
    // ... the same for isoTemperature
    func_domain_isoTemp = new FunctionType( domain_tuple, isoTemperature);
    // Create the domain Set
    // Use LinearDSet(MathType type, double first1, double last1, int lengthX,
    //				     double first2, double last2, int lengthY)
    domain_set = new Linear2DSet(domain_tuple, x1min, x1max, NROWS,
    					      x2min, x2max, NCOLS);
    // Get the Set samples to facilitate the calculations

    float[][] set_samples = domain_set.getSamples( true );
    // The actual temperature values are stored in this array
    // float[1][ number_of_samples ]
    double x[]=new double[2];
    float[][] z_j = new float[1][NCOLS * NROWS];

    // We fill our 'flat' array with the generated values
    // by looping over NCOLS and NROWS

    for(int c = 0; c < NCOLS; c++)
      {x[0]=x1min+(x1max-x1min)/(double)NCOLS*(double)c;
      for(int r = 0; r < NROWS; r++)
        {x[1]=x2min+(x2max-x2min)/(double)NROWS*(double)r;
	     z_j[0][ c * NROWS + r ] = (float)f.func(x);
        }
      }
    // Create the FlatFields
    // Use FlatField(FunctionType type, Set domain_set)

    // For the colored image

    vals_ff = new FlatField( func_domain_temp, domain_set);

    // ...and put the values above into it
    // Note the argument false, meaning that the array won't be copied

    vals_ff.setSamples( z_j , false );


      // ...and for the isocontours

    iso_vals_ff = new FlatField( func_domain_isoTemp, domain_set);


    // Get the values from the temperature FlatField
    // create flat_isoVals array for clarity's sake
    // "false" argument means "don't copy"

    float[][] flat_isoVals = vals_ff.getFloats(false);


    // ...and put the values above into it

    // Note the argument false, meaning that the array won't be copied again

    iso_vals_ff.setSamples( flat_isoVals , false );



    // Create Display and its maps

    // A 2D display

    display = new DisplayImplJ2D(s3);

    // Get display's graphics mode control and draw scales

    GraphicsModeControl dispGMC = (GraphicsModeControl)  display.getGraphicsModeControl();
    dispGMC.setScaleEnable(true);



    // Create the ScalarMaps: latitude to YAxis, longitude to XAxis and
    // temperature to RGB and
    // isoTemperature to IsoContour
    // Use ScalarMap(ScalarType scalar, DisplayRealType display_scalar)

    latMap = new ScalarMap( latitude,    Display.XAxis );
    lonMap = new ScalarMap( longitude, Display.YAxis );

    tempIsoMap = new ScalarMap( isoTemperature,  Display.IsoContour );
    tempRGBMap = new ScalarMap( temperature,  Display.RGB );


    // Add maps to display

    display.addMap( latMap );
    display.addMap( lonMap );

    display.addMap( tempIsoMap );
    display.addMap( tempRGBMap );

    // The ContourControl
    // Note that we get the control from the IsoContour map

    ContourControl isoControl = (ContourControl) tempIsoMap.getControl();

    // Define some parameters for contour lines

    float interval = (float)((x1max-x1min)/NCONTOUR);  // interval between lines

    float lowValue = (float)x1min;   // lowest value

    float highValue = (float)x1max;    // highest value

    float base = (float)x1min;        //  starting at this base value

    // ...and set the lines with the method

    isoControl.setContourInterval(interval, lowValue, highValue, base);
    isoControl.enableLabels(true);

    // Create data references and set the FlatField as our data

    data_ref = new DataReferenceImpl("data_ref");
    iso_data_ref = new DataReferenceImpl("iso_data_ref");

    data_ref.setData( vals_ff );
    iso_data_ref.setData( iso_vals_ff );

    // Add reference to display


    display.addReference( iso_data_ref );
    display.addReference( data_ref );

    // Create application window and add display to window

    JFrame jframe = new JFrame(s3);
    jframe.getContentPane().add(display.getComponent());


    // Set window size and make it visible

    jframe.setSize(400, 400);
    jframe.setVisible(true);
	}

  public static void contour_Plot(f_xj f, double x1min,double x1max,double x2min,double x2max,int NROWS,int NCOLS,int NCONTOUR,String s1,String s2,String s3)
    throws RemoteException, VisADException {
  RealType longitude, latitude;
  RealType temperature;
  // Tuple to pack longitude and latitude together, as the domain
  RealTupleType domain_tuple;
  // The function (domain_tuple -> temperature )
  // Remeber, range is only "temperature"
  FunctionType func_domain_range;
   // Our Data values for the domain are represented by the Set
  Set domain_set;
  // The Data class FlatField
  FlatField vals_ff;
  // The DataReference from data to display
  DataReferenceImpl data_ref;
  // The 2D display, and its the maps
  DisplayImpl display;
  ScalarMap latMap, lonMap;
  ScalarMap tempIsoMap, tempRGBMap;
    // Create the quantities
    // Use RealType(String name);

    latitude =  RealType.getRealType(s1);
    longitude = RealType.getRealType(s2);
    

    domain_tuple = new RealTupleType(latitude, longitude);

    temperature = RealType.getRealType("temperature");

    // Create a FunctionType (domain_tuple -> range_tuple )
    // Use FunctionType(MathType domain, MathType range)

    func_domain_range = new FunctionType( domain_tuple, temperature);

    // Create the domain Set
    // Use LinearDSet(MathType type, double first1, double last1, int lengthX,
    //				     double first2, double last2, int lengthY)

    //int NCOLS = 50;
    //int NROWS = NCOLS;

    domain_set = new Linear2DSet(domain_tuple, x1min, x1max, NROWS,
    					      x2min, x2max, NCOLS);
    // Get the Set samples to facilitate the calculations

    float[][] set_samples = domain_set.getSamples( true );


    // The actual temperature values are stored in this array
    // float[1][ number_of_samples ]
    double x[]=new double[2];
    float[][] z_j = new float[1][NCOLS * NROWS];

    // We fill our 'flat' array with the generated values
    // by looping over NCOLS and NROWS

    for(int c = 0; c < NCOLS; c++)
      {x[0]=x1min+(x1max-x1min)/(double)NCOLS*(double)c;
      for(int r = 0; r < NROWS; r++)
        {x[1]=x2min+(x2max-x2min)/(double)NROWS*(double)r;
	     z_j[0][ c * NROWS + r ] = (float)f.func(x);
        }
      }
	      // Create a FlatField
    // Use FlatField(FunctionType type, Set domain_set)

    vals_ff = new FlatField( func_domain_range, domain_set);

    // ...and put the values above into it

    // Note the argument false, meaning that the array won't be copied

    vals_ff.setSamples( z_j , false );

    // Create Display and its maps

    // A 2D display

    display = new DisplayImplJ2D(s3);

    // Get display's graphics mode control and draw scales

    GraphicsModeControl dispGMC = (GraphicsModeControl)  display.getGraphicsModeControl();
    dispGMC.setScaleEnable(true);


    // Create the ScalarMaps: latitude to YAxis, longitude to XAxis and
    // temperature to IsoContour and eventualy to RGB
    // Use ScalarMap(ScalarType scalar, DisplayRealType display_scalar)

    latMap = new ScalarMap( latitude,    Display.XAxis );
    lonMap = new ScalarMap( longitude,   Display.YAxis );

    // This is new!

    tempIsoMap = new ScalarMap( temperature,  Display.IsoContour );

    // this ScalarMap will color the isolines
    // don't foget to add it to the display

    tempRGBMap = new ScalarMap( temperature,  Display.RGB );


    // Add maps to display

    display.addMap( latMap );
    display.addMap( lonMap );

    display.addMap( tempIsoMap );
    display.addMap( tempRGBMap );


    // Create a data reference and set the FlatField as our data
    data_ref = new DataReferenceImpl("data_ref");

    data_ref.setData( vals_ff );

    // Add reference to display

    display.addReference( data_ref );
    // Create application window and add display to window
    JFrame jframe = new JFrame(s3);
    jframe.getContentPane().add(display.getComponent());
    jframe.setSize(300, 300);
    jframe.setVisible(true);
  }
  
    public static void contour_Plot(double a[][], double x1min,double x1max,double x2min,double x2max,int NROWS,int NCOLS,int NCONTOUR,String s1,String s2,String s3)
    throws RemoteException, VisADException {
  RealType longitude, latitude;
  RealType temperature;
  // Tuple to pack longitude and latitude together, as the domain
  RealTupleType domain_tuple;
  // The function (domain_tuple -> temperature )
  // Remeber, range is only "temperature"
  FunctionType func_domain_range;
   // Our Data values for the domain are represented by the Set
  Set domain_set;
  // The Data class FlatField
  FlatField vals_ff;
  // The DataReference from data to display
  DataReferenceImpl data_ref;
  // The 2D display, and its the maps
  DisplayImpl display;
  ScalarMap latMap, lonMap;
  ScalarMap tempIsoMap, tempRGBMap;
    // Create the quantities
    // Use RealType(String name);

    latitude =  RealType.getRealType(s1);
    longitude = RealType.getRealType(s2);
    

    domain_tuple = new RealTupleType(latitude, longitude);

    temperature = RealType.getRealType("temperature");

    // Create a FunctionType (domain_tuple -> range_tuple )
    // Use FunctionType(MathType domain, MathType range)

    func_domain_range = new FunctionType( domain_tuple, temperature);

    // Create the domain Set
    // Use LinearDSet(MathType type, double first1, double last1, int lengthX,
    //				     double first2, double last2, int lengthY)

    //int NCOLS = 50;
    //int NROWS = NCOLS;

    domain_set = new Linear2DSet(domain_tuple, x1min, x1max, NROWS,
    					      x2min, x2max, NCOLS);
    // Get the Set samples to facilitate the calculations

    float[][] set_samples = domain_set.getSamples( true );


    // The actual temperature values are stored in this array
    // float[1][ number_of_samples ]
    double x[]=new double[2];
    float[][] z_j = new float[1][NCOLS * NROWS];

    // We fill our 'flat' array with the generated values
    // by looping over NCOLS and NROWS

    for(int c = 0; c < NCOLS; c++)
      {x[0]=x1min+(x1max-x1min)/(double)NCOLS*(double)c;
      for(int r = 0; r < NROWS; r++)
        {x[1]=x2min+(x2max-x2min)/(double)NROWS*(double)r;
	     z_j[0][ c * NROWS + r ] = (float)a[r][c];//(float)f.func(x);
        }
      }
	      // Create a FlatField
    // Use FlatField(FunctionType type, Set domain_set)

    vals_ff = new FlatField( func_domain_range, domain_set);

    // ...and put the values above into it

    // Note the argument false, meaning that the array won't be copied

    vals_ff.setSamples( z_j , false );

    // Create Display and its maps

    // A 2D display

    display = new DisplayImplJ2D(s3);

    // Get display's graphics mode control and draw scales

    GraphicsModeControl dispGMC = (GraphicsModeControl)  display.getGraphicsModeControl();
    dispGMC.setScaleEnable(true);


    // Create the ScalarMaps: latitude to YAxis, longitude to XAxis and
    // temperature to IsoContour and eventualy to RGB
    // Use ScalarMap(ScalarType scalar, DisplayRealType display_scalar)

    latMap = new ScalarMap( latitude,    Display.XAxis );
    lonMap = new ScalarMap( longitude,   Display.YAxis );

    // This is new!

    tempIsoMap = new ScalarMap( temperature,  Display.IsoContour );

    // this ScalarMap will color the isolines
    // don't foget to add it to the display

    tempRGBMap = new ScalarMap( temperature,  Display.RGB );


    // Add maps to display

    display.addMap( latMap );
    display.addMap( lonMap );

    display.addMap( tempIsoMap );
    display.addMap( tempRGBMap );


    // Create a data reference and set the FlatField as our data
    data_ref = new DataReferenceImpl("data_ref");

    data_ref.setData( vals_ff );

    // Add reference to display

    display.addReference( data_ref );
    // Create application window and add display to window
    JFrame jframe = new JFrame(s3);
    jframe.getContentPane().add(display.getComponent());
    jframe.setSize(300, 300);
    jframe.setVisible(true);
  }
  
   public static void contour(f_xj f, double x1min,double x1max,double x2min,double x2max,int NROWS,int NCOLS,int NCONTOUR,String s1,String s2,String s3) throws RemoteException, VisADException
   {contour_Plot(f,x1min,x1max,x2min,x2max,NROWS,NCOLS,NCONTOUR,s1,s2,s3);}
   public static void contour(f_xj f, double x1min,double x1max,double x2min,double x2max,String s1,String s2,String s3) throws RemoteException, VisADException
   {contour_Plot(f,x1min,x1max,x2min,x2max,200,200,1,s1,s2,s3);}
   public static void contour(f_xj f, double x1min,double x1max,double x2min,double x2max) throws RemoteException, VisADException
   {contour_Plot(f,x1min,x1max,x2min,x2max,200,200,1,"x","y","z");}
   
   public static void contour(double a[][], double x1min,double x1max,double x2min,double x2max,int NROWS,int NCOLS,int NCONTOUR,String s1,String s2,String s3) throws RemoteException, VisADException
   {contour_Plot(a,x1min,x1max,x2min,x2max,NROWS,NCOLS,NCONTOUR,s1,s2,s3);}
   public static void contour(double a[][], double x1min,double x1max,double x2min,double x2max,String s1,String s2,String s3) throws RemoteException, VisADException
   {contour_Plot(a,x1min,x1max,x2min,x2max,200,200,1,s1,s2,s3);}
   public static void contour(double a[][], double x1min,double x1max,double x2min,double x2max) throws RemoteException, VisADException
   {contour_Plot(a,x1min,x1max,x2min,x2max,200,200,1,"x","y","z");}
   
   public static void func(f_xj f,double x1min,double x1max,double x2min,double x2max,int NCOLS,int NROWS,int NCONTOUR,String sx,String sy,String sz) throws RemoteException, VisADException
   { plot3D_CD1(grid2D(f,x1min,x1max,x2min,x2max,NCOLS, NROWS),x1min,x1max,x2min,x2max,NCONTOUR,sx,sy,sz);}
   public static void func(f_xj f,double x1min,double x1max,double x2min,double x2max,String sx,String sy,String sz) throws RemoteException, VisADException
   { plot3D_CD1(grid2D(f,x1min,x1max,x2min,x2max,200, 200),x1min,x1max,x2min,x2max,1,sx,sy,sz);}
   public static void func(f_xj f,double x1min,double x1max,double x2min,double x2max) throws RemoteException, VisADException
   { plot3D_CD1(grid2D(f,x1min,x1max,x2min,x2max,200, 200),x1min,x1max,x2min,x2max,1,"x","y","z1");}
   	    
   public static void data(double zz[][],double x1min,double x1max,double x2min,double x2max,int NCONTOUR,String sx,String sy,String sz) throws RemoteException, VisADException	    
   { plot3D_CD1(zz,x1min,x1max,x2min,x2max,NCONTOUR,sy,sx,sz);}
   public static void data(double zz[][],double x1min,double x1max,double x2min,double x2max,String sx,String sy,String sz) throws RemoteException, VisADException	    
   { plot3D_CD1(zz,x1min,x1max,x2min,x2max,1,sy,sx,sz);}
   public static void data(double zz[][],double x1min,double x1max,double x2min,double x2max) throws RemoteException, VisADException	    
   { plot3D_CD1(zz,x1min,x1max,x2min,x2max,1,"y","x","z");}
      
  public static void main(String[] args) throws RemoteException, VisADException
  { f1 f=new f1();
  double a[][]=grid2D(f,-1,1,-1,1,20,20);
  contour(f,-1.0,1.0,-1.0,1.0,100,100,100,"x","y","f(x,y)");
  }

} //end of Plot3D
