Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
ego_script [2013/01/07 16:45]
admin [Expression Calculation Syntax]
ego_script [2015/09/14 02:31] (current)
admin [Overview]
Line 11: Line 11:
 A simple EGO script model can be seen below: A simple EGO script model can be seen below:
  
-<​file ​cpp ego1.ego>​+<​file ​java ego1.ego>​
 Script {{ Script {{
   // Loads a GeoTiff map.   // Loads a GeoTiff map.
Line 32: Line 32:
 Here is a slightly more complex example: Here is a slightly more complex example:
  
-<​file ​cpp ego2.ego>​+<​file ​java ego2.ego>​
 Script {{ Script {{
   landscape := LoadCategoricalMap "​c:/​landscape.tif";​   landscape := LoadCategoricalMap "​c:/​landscape.tif";​
-  ​cells hects m2s := CalcAreas landscape;​ +  ​areas := CalcAreas landscape;​ 
-  ​SaveLookupTable hects "c:/area_in_hectares.csv";+  ​SaveTable areas "c:/areas.csv";
 }}; }};
 </​file>​ </​file>​
  
-Note that functor [[Calc Areas]] produces ​three lookup tables, representing the calculated area in cells, hectares and square meters.+Note that functor [[Calc Areas]] produces ​a table, representing the calculated area in cells, hectares and square meters.
  
 It is possible to omit variables representing outputs or ignore them using the variable ''​_''​ (underline). So the previous example can be re-written as shown below: It is possible to omit variables representing outputs or ignore them using the variable ''​_''​ (underline). So the previous example can be re-written as shown below:
  
-<​file ​cpp ego3.ego>​+<​file ​java ego3.ego>​
 Script {{ Script {{
   landscape := LoadCategoricalMap "​c:/​landscape.tif";​   landscape := LoadCategoricalMap "​c:/​landscape.tif";​
Line 64: Line 64:
 It is also possible to use the input and output names to bind variables and parameters. The previous example can be rewritten as It is also possible to use the input and output names to bind variables and parameters. The previous example can be rewritten as
  
-<​file ​cpp ego4.ego>​+<​file ​java ego4.ego>​
 Script {{ Script {{
   { landscape=map } := LoadCategoricalMap { filename="​c:/​landscape.tif"​ };   { landscape=map } := LoadCategoricalMap { filename="​c:/​landscape.tif"​ };
Line 78: Line 78:
 It is possible to freely mix both styles. So you can write the previous input as It is possible to freely mix both styles. So you can write the previous input as
  
-<​file ​cpp ego4.ego>​+<​file ​java ego4.ego>​
 Script {{ Script {{
   landscape := LoadCategoricalMap { filename="​c:/​landscape.tif"​ };   landscape := LoadCategoricalMap { filename="​c:/​landscape.tif"​ };
Line 88: Line 88:
 It is also possible to inline a definition of functor pretty much like nesting function calls in other programming languages: It is also possible to inline a definition of functor pretty much like nesting function calls in other programming languages:
  
-<​file ​cpp ego5.ego>​+<​file ​java ego5.ego>​
 Script {{ Script {{
   { hects=cellAreaInHectares } := CalcAreas (LoadCategoricalMap { filename="​c:/​landscape.tif"​ });   { hects=cellAreaInHectares } := CalcAreas (LoadCategoricalMap { filename="​c:/​landscape.tif"​ });
Line 103: Line 103:
 You can define a single line comment preceding the text with a '​%%//​%%'​. You can define a single line comment preceding the text with a '​%%//​%%'​.
  
-<​code ​cpp>+<​code ​java>
 // This is a single line comment. // This is a single line comment.
 </​code>​ </​code>​
Line 109: Line 109:
 Multi-line comments can be defined surrounding the text with '​%%/​*%%'​ and '​%%*/​%%'​. Multi-line comments can be defined surrounding the text with '​%%/​*%%'​ and '​%%*/​%%'​.
  
-<​code ​cpp>+<​code ​java>
 /* This is a multi-line /* This is a multi-line
 comment */ comment */
Line 116: Line 116:
 It is worth noting that there is a very important difference between both comment styles: multi-line comment style are not preserved if the model is opened using the graphical interface. Usually this is not a problem since multi-line comment can be defined using the '​%%//​%%'​ style. Ex: It is worth noting that there is a very important difference between both comment styles: multi-line comment style are not preserved if the model is opened using the graphical interface. Usually this is not a problem since multi-line comment can be defined using the '​%%//​%%'​ style. Ex:
  
-<​code ​cpp>+<​code ​java>
 // This is a multi-line // This is a multi-line
 // comment // comment
Line 125: Line 125:
 The sequence ''​===''​ is used to separate the brief and extended comments of a functor. The sequence ''​===''​ is used to separate the brief and extended comments of a functor.
  
-<​code ​cpp>+<​code ​java>
 // Generate the initial '​seed' ​ // Generate the initial '​seed' ​
 // //
Line 165: Line 165:
  
 The first syntax represents properties using comments. The first syntax represents properties using comments.
-<​code ​cpp>+<​code ​java>
 /** name = value */ /** name = value */
 </​code>​ </​code>​
Line 171: Line 171:
 The other syntax uses the special symbol @. The other syntax uses the special symbol @.
  
-<​code ​cpp>+<​code ​java>
 @name = value @name = value
 </​code>​ </​code>​
Line 179: Line 179:
 Examples of properties can be seen below: Examples of properties can be seen below:
  
-<​code ​cpp>+<​code ​java>
 /** /**
   dff.date = Wed Oct 21 18:19:21 2009   dff.date = Wed Oct 21 18:19:21 2009
Line 195: Line 195:
 </​code>​ </​code>​
  
-<​code ​cpp>+<​code ​java>
 @alias = Largest Patch Area @alias = Largest Patch Area
 @collapsed = yes @collapsed = yes
Line 232: Line 232:
 The syntax The syntax
  
-<​code ​cpp>+<​code ​java>
 // The input map.  // The input map. 
 // //
Line 240: Line 240:
 and and
  
-<​code ​cpp>+<​code ​java>
 @comment = "The input map.  @comment = "The input map. 
  
Line 255: Line 255:
 Since Dinamica EGO version 2.0, expressions in EGO Script can be represented using an additional special syntax. The example below illustrates:​ Since Dinamica EGO version 2.0, expressions in EGO Script can be represented using an additional special syntax. The example below illustrates:​
  
-<​code ​cpp>+<​code ​java>
 if #random <= ($mean - $min) / ($max - $min) then if #random <= ($mean - $min) / ($max - $min) then
    $min + sqrt(#​random * ($max - $min) * ($mean - $min))    $min + sqrt(#​random * ($max - $min) * ($mean - $min))
Line 265: Line 265:
  
 The use of sigils has some advantages including making easy to determine the data type represented by the variables. They also prevent clashes between special names like "​rand",​ "​line"​ and "​column"​ and the user defined ones. ((Using sigils the expression "rand + #rand" is the sum of a random value with a the value of map named "​rand"​)) The use of sigils has some advantages including making easy to determine the data type represented by the variables. They also prevent clashes between special names like "​rand",​ "​line"​ and "​column"​ and the user defined ones. ((Using sigils the expression "rand + #rand" is the sum of a random value with a the value of map named "​rand"​))
- 
-//However, keep in mind that this syntax is not fully compatible with the graphical interface and you may end up having an invalid model if you edit a model created using this syntax in the graphical interface.//​ 
  
 === Examples === === Examples ===
Line 272: Line 270:
 The example below represents a fragment of a real model using the original syntax: The example below represents a fragment of a real model using the original syntax:
  
-<​code ​cpp>+<​code ​java>
     patches := LoadCategoricalMap "​../​originals/​landscape.ers"​ .no .no 0 0 .none;     patches := LoadCategoricalMap "​../​originals/​landscape.ers"​ .no .no 0 0 .none;
     // ...     // ...
Line 291: Line 289:
 The model modified to use the special expression calculation syntax can be seen below: The model modified to use the special expression calculation syntax can be seen below:
  
-<​code ​cpp>+<​code ​java>
     patches := LoadCategoricalMap "​../​originals/​landscape.ers"​ .no .no 0 0 .none;     patches := LoadCategoricalMap "​../​originals/​landscape.ers"​ .no .no 0 0 .none;
     // ...     // ...
Line 303: Line 301:
 ===== Complex Example ===== ===== Complex Example =====
  
-<​code ​csharp>+<​code ​java>
 @title = Calc Patch Sizes, Mean Patch Sizes and Patch Size Standard Deviations @title = Calc Patch Sizes, Mean Patch Sizes and Patch Size Standard Deviations
 @author = Dinamica Team @author = Dinamica Team