package JavaFoilEmbedding;

// JavaFoil.jar
import MH.JavaFoil.*;

/**
 * <p>JavaFoil Embedded.</p>
 * <p>Example for embedding JavaFoil into a Java frameworks</p>
 * <p>Copyright (c) 2007-2009 MH AeroTools</p>
 * <p>
 * JavaFoil can be embedded into other Java applications. Using the scripting
 * interface it is possible to execute scripts directly without having to
 * run javaFoil in batch mode. This reduced startup time when many runs are
 * needed and makes it possible to automate tedious tasks.
 * </p>
 * <p>
 * Note that JavaFoil.jar as well as MHClasses.jar are required.
 * </p>
 *
 * @author Martin Hepperle
 * @version 1.0 (May 2007)
 */
public class JavaFoilEmbeddingExample
{
   /**
    * The main method, called at startup to create an JavaFoilEmbeddingExample object.
    * @param args String[] - not used
    */
   public static void main ( String[] args )
   {
      JavaFoilEmbeddingExample theExample = new JavaFoilEmbeddingExample ();
   }


   /**
    * This object demonstrates how to
    * <ul>
    * <li>create a JavaFoil object,</li>
    * <li>execute script commands,</li>
    * <li>use the log file,</li>
    * <li>terminate JavaFoil correctly.</li>
    * </ul>
    * <h4>Example code:</h4>
    * <hr>
    * <pre>
    *       // STEP 1: import required classes from jar file
    *       // Note: Java 1.5 or higher required
    *       //
    *       // JavaFoil.jar
    *       import MH.JavaFoil.*;
    * <br>
    *       // STEP 2: create a new instance of JavaFoil
    *       JavaFoil jf = new JavaFoil();
    * <br>
    *       // STEP 3: perform startup initialization (must be done, important!)
    *       // this variant does not create a log file
    *       jf.startEmbedded();
    *       // this alternative variant creates a log file
    *       //jf.startEmbedded("filename.log");
    * <br>
    *       // STEP 4-N: now run script commands as usual
    *       // define the country settings so that the correct separator
    *       // character and decimal characters are used (here: ';', resp. '.')
    *       jf.runScriptLine("Options.Country(0)");
    *       jf.runScriptLine("Geometry.CreateAirfoil(0;61;12;30;0.000;40.000;0;0;1)");
    * <br>
    *       jf.runScriptLine("Polar.Analyze(500000;500000;100000;-5;15;1;100;100;0;0)");
    *       jf.runScriptLine("Polar.Save(\"Z:/polar.txt\")");
    * <br>
    *       // Let's generate an error.
    *       // As no log file exists, an error dialog is displayed
    *       jf.runScriptLine("SetLogFile(\"\\//THIS*?is*@no@*?validfilename\")");
    * <br>
    *       // Create a log file which will be used for following commands
    *       jf.runScriptLine("SetLogFile(\"JavaFoil.log\")");
    *       // generate an error
    *       jf.runScriptLine("Can this be wrong");
    *       jf.runScriptLine("");
    * <br>
    *       // STEP N+1: Terminate JavaFoil
    *       jf.exitEmbedded ();
    *       // WARNING:
    *       // You should NOT use the Exit() script command because this will exit
    *       // your application too.
    * <br>
    *       // STEP N+2: Optional: set jf to null in order to release memory.
    *       jf  = null;
    * </pre>
    * <hr>
    */
   public JavaFoilEmbeddingExample ()
   {
      // Create a new instance of JavaFoil
      JavaFoil jf = new JavaFoil ();

      // Perform startup initialization (must be done, important!)
      // this variant creates a log file named "JavaFoil.log"
      // in the "current" directory
      jf.startEmbedded ();
      // this alternative variant creates a log file with a specific path
      //jf.startEmbedded("Z:/filename.log");

      // Run script commands as usual
      //
      // note that Country(0) sets token separator to ';'
      // and the decimal character to '.' (US-format)
      // if you do not include this, your app nay not run on
      // non-US Locale's
      jf.runScriptLine ( "Options.Country(0)" );
      //
      jf.runScriptLine (
         "Geometry.CreateAirfoil(0;121;12;30;0.000;40.000;0;0;1)" );
      //
      jf.runScriptLine (
         "Polar.Analyze(500000;500000;100000;-5;15;1;100;100;0;0)" );
      //
      jf.runScriptLine ( "Polar.Save(\"Z:/polar.txt\")" );

      // Now generate an error
      jf.runScriptLine ( "Can this be wrong" );

      // You should NOT use the Exit() script command because this will exit
      // your application too.
      // NOT: jf.runScriptLine("Exit()");

      jf.exitEmbedded ();
      jf = null;
   }
}
