# Common Report Components

COMMAND FILE:
  CFX Post Version = 11.0
END

# Turn on debugging information
#!$TURBO_REPORT_DEBUG = 1;

! no warnings 'redefine';

#### initTurbo
!sub initTurbo
!{
> turbo init
> turbo more_vars
!}

#### getDomainInfo
!sub getDomainInfo
!{
!  if ( defined($TURBO_REPORT_DEBUG) && $TURBO_REPORT_DEBUG > 0 )
!  {
!    print "getDomainInfo\n";
!  }

!  my $currentCaseList = getValue("DATA READER","Current Case List");
!  my @cases=split(/,/,"$currentCaseList");
!  if (!@cases) {
!    return;
!  }
!  my $temp = getValue("/DATA READER/CASE:$cases[0]","Flow Type");
!  $flowType = "Incompressible";
!  if ( defined($temp) )
!  {
!    $flowType = $temp;
!  }
!  elsif ( objectExists("/SCALAR VARIABLE:Total Enthalpy") )
!  {
!    $flowType = "Compressible";
!  }


#  Get domain info
!  my $alldomainlist=getValue('All Domains', 'Member List');
!  my @domains=split(/,/,"$alldomainlist");
!  $domain = $domains[0];

#  Get rotation axis

!  my $rotAxisFromString = getValue("$domain", 'Rotation Axis From');
!  my $rotAxisToString = getValue("$domain", 'Rotation Axis To');
!  if ( defined($rotAxisFromString) && defined($rotAxisToString) )
!  {
!    $rotAxisFromString =~ s/(\s*\[(.*?)\])//g;
!    my @rotAxisFrom = split(/,\s/, "$rotAxisFromString");
!    $rotAxisToString =~ s/(\s*\[(.*?)\])//g;
!    @rotAxis = split(/,\s/, "$rotAxisToString");
!    $rotAxis[0] -= $rotAxisFrom[0];
!    $rotAxis[1] -= $rotAxisFrom[1];
!    $rotAxis[2] -= $rotAxisFrom[2];
!    my $rotAxisInvMag = 1/sqrt($rotAxis[0]**2 + $rotAxis[1]**2 + $rotAxis[2]**2);
!    $rotAxis[0] *= $rotAxisInvMag;
!    $rotAxis[1] *= $rotAxisInvMag;
!    $rotAxis[2] *= $rotAxisInvMag;
!  }
!  else
!  {
!    @rotAxis = ( 0, 0, 1);  # Assume Z-axis if none specified
!  }    

#  Get number of components

!  $numPassages = int(getValue("$domain", 'Number of Passages in 360'));
!  $numPassPerComp = int(getValue("$domain", 'Number of Passages in Component'));
!  $numComponents = $numPassages / $numPassPerComp;
!  $numCopies = int($numComponents);

#  Get regions

!  $regionBlade = createCalcLocator('Calc Blade Region', getValue("$domain", 'Blade Region'));
!  $regionHub = createCalcLocator('Calc Hub Region', getValue("$domain", 'Hub Region'));
!  $regionShroud = createCalcLocator('Calc Shroud Region', getValue("$domain", 'Shroud Region'));
!  $regionInlet = createCalcLocator('Calc Inlet Region', getValue("$domain", 'Inlet Region'));
!  $regionOutlet = createCalcLocator('Calc Outlet Region', getValue("$domain", 'Outlet Region'));
!  $regionStreamLE = 'Stream Blade LE';
!  $regionStreamTE = 'Stream Blade TE';
!  $regionWalls = createCalcLocator('Calc Wall Region', "$regionBlade, $regionHub, $regionShroud");

!  if ( defined($TURBO_REPORT_DEBUG) && $TURBO_REPORT_DEBUG > 0 )
!  {
!    print "domain = $domain\n";
!    print "flowType = $flowType\n";
!    print "rotAxis = @rotAxis\n";
!    print "numPassages = $numPassages\n";
!    print "numPassPerComp = $numPassPerComp\n";
!    print "numComponents = $numComponents\n";
!    print "numCopies = $numCopies\n";
!    print "regionBlade = $regionBlade\n";
!    print "regionHub = $regionHub\n";
!    print "regionShroud = $regionShroud\n";
!    print "regionInlet = $regionInlet\n";
!    print "regionOutlet = $regionOutlet\n";
!    print "regionStreamLE = $regionStreamLE\n";
!    print "regionStreamTE = $regionStreamTE\n";
!    print "regionWalls = $regionWalls\n";
!  }

# Find the range of Streamwise Location

!  my $units;
!  $locStreamMin = 0;
!  $locStreamMax = 1;
!  if ( objectExists('/SCALAR VARIABLE:Streamwise Location') )
!  {
!    ($locStreamMin, $units) = evaluate( "minVal(Streamwise Location)\@$domain" );
!    ($locStreamMax, $units) = evaluate( "maxVal(Streamwise Location)\@$domain" );
!  }
!  my $streamOffset = 0.251;
!  $locStreamLE = $locStreamMin + $streamOffset;
!  $locStreamTE = $locStreamMax - $streamOffset;

# Create the streamwise leading and trailing edge regions

!  hiddenStreamwiseSurface( $regionStreamLE, $locStreamLE );
!  hiddenStreamwiseSurface( $regionStreamTE, $locStreamTE );

# Set the blade-to-blade span locations

!  $locSpanLow = 0.2;
!  $locSpanMid = 0.5;
!  $locSpanHigh = 0.8;
!}

#### createCalcLocator
!sub createCalcLocator
!{
!  my ($locatorName, $locatorStr) = @_;
!  my @locators = split(/\s*,\s*/,$locatorStr);

!  if ( @locators < 1 )
!  {
!    reportError( "Empty locator list." );
!    return $locatorName;
!  }
!  if ( @locators > 1 )
!  {
SURFACE GROUP:$locatorName
  Apply Instancing Transform = Off
  Colour Mode = Constant
  Domain List = $domain
  Location List = $locatorStr
  Draw Faces = Off
  Draw Lines = Off
END
>hide $locatorName
!    return $locatorName;
!  }
!  else
!  {
!    return $locatorStr;
!  }
!}

#### setDomainTransform
!sub setDomainTransform
!{
DOMAIN:$domain
  Number of Copies = 1
END
INSTANCE TRANSFORM:Two Blades Transform
  Apply Rotation = On
  Instancing Info From Domain = Off
  Number of Copies = 2
  Number of Passages in 360 = $numPassages
  Number of Passages in Component = $numPassPerComp
  Rotation Axis Type = Rotation Axis
  Rotation Axis From = 0 [m], 0 [m], 0 [m]
  Rotation Axis To = $rotAxis[0] [m], $rotAxis[1] [m], $rotAxis[2] [m]
END
INSTANCE TRANSFORM:Three Blades Transform
  Apply Rotation = On
  Instancing Info From Domain = Off
  Number of Copies = 3
  Number of Passages in 360 = $numPassages
  Number of Passages in Component = $numPassPerComp
  Rotation Axis Type = Rotation Axis
  Rotation Axis From = 0 [m], 0 [m], 0 [m]
  Rotation Axis To = $rotAxis[0] [m], $rotAxis[1] [m], $rotAxis[2] [m]
END
INSTANCE TRANSFORM:All Blades Transform
  Apply Rotation = On
  Instancing Info From Domain = Off
  Number of Copies = $numCopies
  Number of Passages in 360 = $numPassages
  Number of Passages in Component = $numPassPerComp
  Rotation Axis Type = Rotation Axis
  Rotation Axis From = 0 [m], 0 [m], 0 [m]
  Rotation Axis To = $rotAxis[0] [m], $rotAxis[1] [m], $rotAxis[2] [m]
END
!}


#### Report CCL Object
REPORT:
  FILE INFORMATION OPTIONS:
    Include In Report = true
    This Exists = true
  END
  MESH STATISTICS OPTIONS:
    Include In Report = true
    Show Connectivity Number = Off
    Show Edge Length Ratio = On
    Show Element Volume Ratio = Off
    Show Max Face Angle = Off
    Show Min Face Angle = Off
    Show Number of Elements = On
    Show Number of Hexahedra = Off
    Show Number of Nodes = On
    Show Number of Pyramids = Off
    Show Number of Tetrahedra = Off
    Show Number of Wedges = Off
    Show Number of Polyhedra = Off
    This Exists = true
  END
  PHYSICS SUMMARY OPTIONS:
    Include In Report = true
    Show Boundary Physics = On
    Show Domain Physics = On
    This Exists = true
  END
  SOLUTION SUMMARY OPTIONS:
    Include In Report = false
    Show Boundary Flow Summary = On
    Show Force and Torque Summary = Off
    Show Forces = true
    Show Torques = true
    This Exists = true
  END
  PREVIEW:
    This Exists = true
    OUTPUT SETTINGS:
      Chart Image Type = png
      Chart Size = Custom
      Custom Chart Size Height = 384
      Custom Chart Size Width = 480
      Custom Figure Size Height = 576
      Custom Figure Size Width = 720
      Figure Image Type = png
      Figure Size = Custom
      Fit Views = Off
      This Exists = false
    END
  END
  PUBLISH:
    Report Format = HTML
    Save Images In Separate Folder = true
    This Exists = true
    OUTPUT SETTINGS:
      Chart Image Type = png
      Chart Size = Custom
      Custom Chart Size Height = 384
      Custom Chart Size Width = 480
      Custom Figure Size Height = 576
      Custom Figure Size Width = 720
      Figure Image Type = png
      Figure Size = Custom
      Fit Views = Off
      This Exists = false
    END
  END
END
TITLE PAGE:
  Include ANSYS Logo = On
  Include Custom Logo = Off
  Include Date = On
  Include TOC = On
  Show Captions in TOC = true
  Title Page Exists = true
END


# Common Subroutines


#### header
!sub header
!{
!  my ($name, $heading, $level, $comment) = @_;
!  if ( defined($TURBO_REPORT_DEBUG) && $TURBO_REPORT_DEBUG > 0 )
!  {
!    print "header( $name, $heading, $level, $comment)\n";
!  }
COMMENT:$name
  Comment Heading = $heading
  Comment Text = <p>$comment</p>
  Heading Level = $level
END
!}
!sub shortheader1
!{
!  my ($heading) = @_;
!  header($heading, $heading, 1, "");
!}
!sub shortheader2
!{
!  my ($heading) = @_;
!  header($heading, $heading, 2, "");
!}


#### commonCEL
!sub commonCEL
!{
!  if ( defined($TURBO_REPORT_DEBUG) && $TURBO_REPORT_DEBUG > 0 )
!  {
!    print "commonCEL()\n";
!  }

LIBRARY:
 CEL:
  EXPRESSIONS:

## Common expressions for all cases

   numComponents = $numComponents
   mfr = massFlow()@$regionInlet * numComponents
   D te = 2*areaAve(Radius)@$regionStreamTE
   Cm in = areaAve(Velocity Meridional)@$regionInlet
   Cm le = areaAve(Velocity Meridional)@$regionStreamLE
   Cm te = areaAve(Velocity Meridional)@$regionStreamTE
   Cm out = areaAve(Velocity Meridional)@$regionOutlet
   P in = areaAve(Pressure)@$regionInlet + Reference Pressure
   P le = areaAve(Pressure)@$regionStreamLE + Reference Pressure
   P te = areaAve(Pressure)@$regionStreamTE + Reference Pressure
   P out = areaAve(Pressure)@$regionOutlet + Reference Pressure
   rho in = areaAve(Density)@$regionInlet
   rho le = areaAve(Density)@$regionStreamLE
   rho te = areaAve(Density)@$regionStreamTE
   rho out = areaAve(Density)@$regionOutlet
   Sigma in = areaAve(Velocity Cubed)@$regionInlet / C in^3
   Sigma le = areaAve(Velocity Cubed)@$regionStreamLE / C le^3
   Sigma te = areaAve(Velocity Cubed)@$regionStreamTE / C te^3
   Sigma out = areaAve(Velocity Cubed)@$regionOutlet / C out^3
   
!  if ( $isRotor )
!  {
!    my $omegaAbs;
!    my $omega1;
!    my $omega2;
!    my $omegaUnits;
!    my $val;
!    ($omegaAbs, $omegaUnits) = evaluate( "abs(omega)" );
!    ($val, $dummy) = evaluate( "1 [rad]" );
!    if ( $val == 1 )
!    {
!      $omega1 = "$omegaAbs [$omegaUnits] / 1 [rad]";
!    }
!    else
!    {
!      $omega1 = "$omegaAbs [$omegaUnits]  * pi / 180 [degree]";
!    }
     n = $omega1

!    ($omega2, $omegaUnits) = evaluate( "omega" );
!    if ( $omega2 < 0 )
!    {
       Alpha = Velocity in Stn Frame Flow Angle - 90 [degree]
       Beta = Velocity Flow Angle - 90 [degree] 
!    }
!    else
!    {
       Alpha = 90 [degree] - Velocity in Stn Frame Flow Angle
       Beta = 90 [degree] - Velocity Flow Angle
!    }
     C cubed = Velocity in Stn Frame ^ 3
     Alpha in = areaAve(Alpha)@$regionInlet
     Alpha le = areaAve(Alpha)@$regionStreamLE
     Alpha te = areaAve(Alpha)@$regionStreamTE
     Alpha out = areaAve(Alpha)@$regionOutlet
     Beta in = areaAve(Beta)@$regionInlet
     Beta le = areaAve(Beta)@$regionStreamLE
     Beta te = areaAve(Beta)@$regionStreamTE
     Beta out = areaAve(Beta)@$regionOutlet
     C in = areaAve(Velocity in Stn Frame)@$regionInlet
     C le = areaAve(Velocity in Stn Frame)@$regionStreamLE
     C te = areaAve(Velocity in Stn Frame)@$regionStreamTE
     C out = areaAve(Velocity in Stn Frame)@$regionOutlet
     Cu in = areaAve(Velocity in Stn Frame Circumferential)@$regionInlet
     Cu le = areaAve(Velocity in Stn Frame Circumferential)@$regionStreamLE
     Cu te = areaAve(Velocity in Stn Frame Circumferential)@$regionStreamTE
     Cu out = areaAve(Velocity in Stn Frame Circumferential)@$regionOutlet
     Pt in = massFlowAve(Total Pressure in Stn Frame)@$regionInlet + Reference Pressure
     Pt le = massFlowAve(Total Pressure in Stn Frame)@$regionStreamLE + Reference Pressure
     Pt te = massFlowAve(Total Pressure in Stn Frame)@$regionStreamTE + Reference Pressure
     Pt out = massFlowAve(Total Pressure in Stn Frame)@$regionOutlet + Reference Pressure
     Ptr in = massFlowAve(Total Pressure)@$regionInlet + Reference Pressure
     Ptr le = massFlowAve(Total Pressure)@$regionStreamLE + Reference Pressure
     Ptr te = massFlowAve(Total Pressure)@$regionStreamTE + Reference Pressure
     Ptr out = massFlowAve(Total Pressure)@$regionOutlet + Reference Pressure
     U in = areaAve(Rotation Velocity)@$regionInlet
     U le = areaAve(Rotation Velocity)@$regionStreamLE
     U te = areaAve(Rotation Velocity)@$regionStreamTE
     U out = areaAve(Rotation Velocity)@$regionOutlet
     W in = areaAve(Velocity)@$regionInlet
     W le = areaAve(Velocity)@$regionStreamLE
     W te = areaAve(Velocity)@$regionStreamTE
     W out = areaAve(Velocity)@$regionOutlet
     Wu in = areaAve(Velocity Circumferential)@$regionInlet
     Wu le = areaAve(Velocity Circumferential)@$regionStreamLE
     Wu te = areaAve(Velocity Circumferential)@$regionStreamTE
     Wu out = areaAve(Velocity Circumferential)@$regionOutlet
     Shaft Power = abs(sum(Velocity in Stn Frame u * Force X + Velocity in Stn Frame v * Force Y + Velocity in Stn Frame w * Force Z)@$regionWalls) * numComponents
!  }
!  else
!  {
     C cubed = Velocity ^ 3
     Beta = 90 [degree] - Velocity Flow Angle
     Beta in = areaAve(Beta)@$regionInlet
     Beta le = areaAve(Beta)@$regionStreamLE
     Beta te = areaAve(Beta)@$regionStreamTE
     Beta out = areaAve(Beta)@$regionOutlet
     C in = areaAve(Velocity)@$regionInlet
     C le = areaAve(Velocity)@$regionStreamLE
     C te = areaAve(Velocity)@$regionStreamTE
     C out = areaAve(Velocity)@$regionOutlet
     Cu in = areaAve(Velocity Circumferential)@$regionInlet
     Cu le = areaAve(Velocity Circumferential)@$regionStreamLE
     Cu te = areaAve(Velocity Circumferential)@$regionStreamTE
     Cu out = areaAve(Velocity Circumferential)@$regionOutlet
     Pt in = massFlowAve(Total Pressure)@$regionInlet + Reference Pressure
     Pt le = massFlowAve(Total Pressure)@$regionStreamLE + Reference Pressure
     Pt te = massFlowAve(Total Pressure)@$regionStreamTE + Reference Pressure
     Pt out = massFlowAve(Total Pressure)@$regionOutlet + Reference Pressure
!  }

!  if ( $flowType eq "Compressible" )
!  {
     T in = massFlowAve(Temperature)@$regionInlet
     T le = massFlowAve(Temperature)@$regionStreamLE
     T te = massFlowAve(Temperature)@$regionStreamTE
     T out = massFlowAve(Temperature)@$regionOutlet
     h in = massFlowAve(Static Enthalpy)@$regionInlet
     h le = massFlowAve(Static Enthalpy)@$regionStreamLE
     h te = massFlowAve(Static Enthalpy)@$regionStreamTE
     h out = massFlowAve(Static Enthalpy)@$regionOutlet
     s in = massFlowAve(Static Entropy)@$regionInlet
     s le = massFlowAve(Static Entropy)@$regionStreamLE
     s te = massFlowAve(Static Entropy)@$regionStreamTE
     s out = massFlowAve(Static Entropy)@$regionOutlet

!    if ( objectExists('/SCALAR VARIABLE:Total Density in Stn Frame') )
!    {
       rho0 in = areaAve(Total Density in Stn Frame)@$regionInlet
       Q0 in = mfr / rho0 in
!    }
!    elsif ( objectExists('/SCALAR VARIABLE:Total Density') )
!    {
       rho0 in = areaAve(Total Density)@$regionInlet
       Q0 in = mfr / rho0 in
!    }
!    elsif ( objectExists('/SCALAR VARIABLE:Specific Heat Capacity at Constant Pressure') && objectExists('/SCALAR VARIABLE:Specific Heat Capacity at Constant Volume') )
!    {
       Rgas = ave(Specific Heat Capacity at Constant Pressure - Specific Heat Capacity at Constant Volume)@$regionInlet
       rho0 in = Pt in / (Rgas * Tt in)
       Q0 in = mfr / rho0 in
!    }
!  }

!  if ( $isRotor && $flowType eq "Compressible" ) 
!  {
     Tt in = massFlowAve(Total Temperature in Stn Frame)@$regionInlet
     Tt le = massFlowAve(Total Temperature in Stn Frame)@$regionStreamLE
     Tt te = massFlowAve(Total Temperature in Stn Frame)@$regionStreamTE
     Tt out = massFlowAve(Total Temperature in Stn Frame)@$regionOutlet
     Ttr in = massFlowAve(Total Temperature)@$regionInlet
     Ttr le = massFlowAve(Total Temperature)@$regionStreamLE
     Ttr te = massFlowAve(Total Temperature)@$regionStreamTE
     Ttr out = massFlowAve(Total Temperature)@$regionOutlet
     H in = massFlowAve(Total Enthalpy in Stn Frame)@$regionInlet
     H le = massFlowAve(Total Enthalpy in Stn Frame)@$regionStreamLE
     H te = massFlowAve(Total Enthalpy in Stn Frame)@$regionStreamTE
     H out = massFlowAve(Total Enthalpy in Stn Frame)@$regionOutlet
     I in = massFlowAve(Rothalpy)@$regionInlet
     I le = massFlowAve(Rothalpy)@$regionStreamLE
     I te = massFlowAve(Rothalpy)@$regionStreamTE
     I out = massFlowAve(Rothalpy)@$regionOutlet
     M abs in = massFlowAve(Mach Number in Stn Frame)@$regionInlet
     M abs le = massFlowAve(Mach Number in Stn Frame)@$regionStreamLE
     M abs te = massFlowAve(Mach Number in Stn Frame)@$regionStreamTE
     M abs out = massFlowAve(Mach Number in Stn Frame)@$regionOutlet
     M rel in = massFlowAve(Mach Number)@$regionInlet
     M rel le = massFlowAve(Mach Number)@$regionStreamLE
     M rel te = massFlowAve(Mach Number)@$regionStreamTE
     M rel out = massFlowAve(Mach Number)@$regionOutlet
!  }

!  if ( !$isRotor && $flowType eq "Compressible" ) 
!  {
     Tt in = massFlowAve(Total Temperature)@$regionInlet
     Tt le = massFlowAve(Total Temperature)@$regionStreamLE
     Tt te = massFlowAve(Total Temperature)@$regionStreamTE
     Tt out = massFlowAve(Total Temperature)@$regionOutlet
     H in = massFlowAve(Total Enthalpy)@$regionInlet
     H le = massFlowAve(Total Enthalpy)@$regionStreamLE
     H te = massFlowAve(Total Enthalpy)@$regionStreamTE
     H out = massFlowAve(Total Enthalpy)@$regionOutlet
     M in = massFlowAve(Mach Number)@$regionInlet
     M le = massFlowAve(Mach Number)@$regionStreamLE
     M te = massFlowAve(Mach Number)@$regionStreamTE
     M out = massFlowAve(Mach Number)@$regionOutlet
!  }

  END
 END
END

USER SCALAR VARIABLE:Velocity Cubed
  Boundary Values = Conservative
  Calculate Global Range = Off
  Expression = C cubed
  Recipe = Expression
  Variable to Copy = Velocity
END
USER SCALAR VARIABLE:Velocity Beta
  Boundary Values = Conservative
  Calculate Global Range = Off
  Expression = Beta
  Recipe = Expression
  Variable to Copy = Velocity
END
!  if ( $isRotor )
!  {
USER SCALAR VARIABLE:Velocity Alpha
  Boundary Values = Conservative
  Calculate Global Range = Off
  Expression = Alpha
  Recipe = Expression
  Variable to Copy = Velocity
END
SCALAR VARIABLE:Velocity in Stn Frame u
  Boundary Values = Hybrid
END
SCALAR VARIABLE:Velocity in Stn Frame v
  Boundary Values = Hybrid
END
SCALAR VARIABLE:Velocity in Stn Frame w
  Boundary Values = Hybrid
END
!  }
!}


#### computedResultsTable
!sub computedResultsTable
!{
!  my ($caption, @vars) = @_;

TABLE:$caption Table
  OBJECT REPORT OPTIONS:
    Report Caption = $caption
  END
  TABLE CELLS:

!  my $varIndex = 0;
!  my $rowStart = 2;
!  while ( @vars > 1 )
!  {
!    my $rowNumber = $varIndex + $rowStart;
!    my $rowName = shift( @vars );
!    my $expression = shift( @vars );
!    my $precision = shift( @vars );
!    if ( exprExists($expression) )
!    {
       A$rowNumber = "$rowName", False, False, False, Left, False, 0, Font Name, 1|1, %7.4f, True, ffffff, 000000, True
       B$rowNumber = "=$expression", False, False, False, Right, False, 0, Font Name, 1|1, $precision, False, ffffff, 000000, True
       C$rowNumber = "=$expression", False, False, False, Left, False, 0, Font Name, 1|1, %7.4f, True, ffffff, 000000, False
!    }
!    else
!    {
       A$rowNumber = "$rowName", False, False, False, Left, False, 0, Font Name, 1|1, %7.4f, True, ffffff, 000000, True
       B$rowNumber = "$expression", False, False, False, Right, False, 0, Font Name, 1|1, $precision, False, ffffff, ff0000, True
!    }
!    $varIndex++;
!  }
  END
END
!}

#### setResultsTableValues
!sub setResultsTableValues
!{
!  my ($caption, @vars) = @_;

TABLE:$caption Table
  OBJECT REPORT OPTIONS:
    Report Caption = $caption
  END
  TABLE CELLS:

!  my $varIndex = 0;
!  my $rowStart = 2;
!  while ( @vars > 1 )
!  {
!    my $rowNumber = $varIndex + $rowStart;
!    my $rowName = shift( @vars );
!    my $cellValue = shift( @vars );

!    if( length( $rowName ) > 0 )
!    {
       A$rowNumber = "$rowName", False, False, False, Left, False, 0, Font Name, 1|1, %7.4f, True, ffffff, 000000, True
!    }
!    if( length( $cellValue ) > 0 )
!    {
       B$rowNumber = "$cellValue", False, False, False, Right, False, 0, Font Name, 1|1, %7.4f, False, ffffff, 000000, True
!    }
!    $varIndex++;
!  }
  END
END
!}

#### SummaryDataTable
!sub summaryDataTable
!{
!  if ( defined($TURBO_REPORT_DEBUG) && $TURBO_REPORT_DEBUG > 0 )
!  {
!    print "summaryDataTable()\n";
!  }

!  my @vars;

!  if ( $isRotor && $flowType eq "Compressible" )
!  {
!    @vars = ('Density', 'rho',
!             'Pstatic', 'P',
!             'Ptotal', 'Pt',
!             'Ptotal (rot)', 'Ptr',
!             'Tstatic', 'T',
!             'Ttotal', 'Tt',
!             'Ttotal (rot)', 'Ttr',
!             'Hstatic', 'h',
!             'Htotal', 'H',
!             'Rothalpy', 'I',
!             'Entropy', 's',
!             'Mach (abs)', 'M abs',
!             'Mach (rel)', 'M rel',
!             'U', 'U',
!             'Cm', 'Cm',
!             'Cu', 'Cu',
!             'C', 'C',
!             'Distortion Parameter', 'Sigma',
!             'Flow Angle: Alpha', 'Alpha',
!             'Wu', 'Wu',
!             'W', 'W',
!             'Flow Angle: Beta', 'Beta');
!  }
!  elsif ( $isRotor && $flowType eq "Incompressible" )
!  {
!    @vars = ('Density', 'rho',
!             'Pstatic', 'P',
!             'Ptotal', 'Pt',
!             'Ptotal (rot)', 'Ptr',
!             'U', 'U',
!             'Cm', 'Cm',
!             'Cu', 'Cu',
!             'C', 'C',
!             'Distortion Parameter', 'Sigma',
!             'Flow Angle: Alpha', 'Alpha',
!             'Wu', 'Wu',
!             'W', 'W',
!             'Flow Angle: Beta', 'Beta');
!  }
!  elsif ( !$isRotor && $flowType eq "Compressible" )
!  {
!    @vars = ('Density', 'rho',
!             'Pstatic', 'P',
!             'Ptotal', 'Pt',
!             'Tstatic', 'T',
!             'Ttotal', 'Tt',
!             'Hstatic', 'h',
!             'Htotal', 'H',
!             'Entropy', 's',
!             'Mach', 'M',
!             'Cm', 'Cm',
!             'Cu', 'Cu',
!             'C', 'C',
!             'Distortion Parameter', 'Sigma',
!             'Flow Angle', 'Beta');
!  }
!  else
!  {
!    @vars = ('Density', 'rho',
!             'Pstatic', 'P',
!             'Ptotal', 'Pt',
!             'Cm', 'Cm',
!             'Cu', 'Cu',
!             'C', 'C',
!             'Distortion Parameter', 'Sigma',
!             'Flow Angle', 'Beta');
!  }


TABLE:Summary Data Table
  OBJECT REPORT OPTIONS:
    Report Caption = Summary Data
  END
  TABLE CELLS:
    A1 = "Quantity", True, False, False, Center, False, 1, Font Name, 1|1, %6.3f, True, ffffff, 000000, True
    B1 = "Inlet", True, False, False, Center, False, 1, Font Name, 1|1, %6.3f, True, ffffff, 000000, True
    C1 = "LE Cut", True, False, False, Center, False, 1, Font Name, 1|1, %6.3f, True, ffffff, 000000, True
    D1 = "TE Cut", True, False, False, Center, False, 1, Font Name, 1|1, %6.3f, True, ffffff, 000000, True
    E1 = "Outlet", True, False, False, Center, False, 1, Font Name, 1|1, %6.3f, True, ffffff, 000000, True
    F1 = "TE/LE", True, False, False, Center, False, 1, Font Name, 1|1, %6.3f, True, ffffff, 000000, True
    G1 = "TE-LE", True, False, False, Center, False, 1, Font Name, 1|1, %6.3f, True, ffffff, 000000, True
    H1 = "Units", True, False, False, Center, False, 1, Font Name, 1|1, %6.3f, True, ffffff, 000000, True

!  my $varIndex = 0;
!  my $rowStart = 2;
!  while ( @vars > 1 )
!  {
!    my $rowNumber = $varIndex + $rowStart;
!    my $rowName = shift( @vars );
!    my $varName = shift( @vars );
!    $varIndex++;

    A$rowNumber = "$rowName", False, False, False, Left, False, 0, Font Name, 1|1, %7.4f, True, ffffff, 000000, True
    B$rowNumber = "=$varName in", False, False, False, Right, False, 0, Font Name, 1|1, %7.4f, False, ffffff, 000000, True
    C$rowNumber = "=$varName le", False, False, False, Right, False, 0, Font Name, 1|1, %7.4f, False, ffffff, 000000, True
    D$rowNumber = "=$varName te", False, False, False, Right, False, 0, Font Name, 1|1, %7.4f, False, ffffff, 000000, True
    E$rowNumber = "=$varName out", False, False, False, Right, False, 0, Font Name, 1|1, %7.4f, False, ffffff, 000000, True
    F$rowNumber = "=$varName te / $varName le", False, False, False, Right, False, 0, Font Name, 1|1, %7.4f, False, ffffff, 000000, True
    G$rowNumber = "=$varName te - $varName le", False, False, False, Right, False, 0, Font Name, 1|1, %7.4f, False, ffffff, 000000, True
    H$rowNumber = "=$varName in", False, False, False, Left, False, 0, Font Name, 1|1, %7.4f, True, ffffff, 000000, False 
!  }

  END
END
!}


#### bladeLoadingChart
!sub bladeLoadingChart
!{
!  my ($name, $varName, $spanFraction) = @_;
!  if ( defined($TURBO_REPORT_DEBUG) && $TURBO_REPORT_DEBUG > 0 )
!  {
!    print "bladeLoadingChart( $name, $varName, $spanFraction )\n";
!  }

# Check that the blade region is a single item or surface group.
# If a surface group, than print warning because they are not supported by
# the intersection calculation.
!  if ( objectExists("/SURFACE GROUP:$regionBlade") )
!  {
!    if ( !objectExists('/COMMENT:Blade Loading Charts') )
!    {
!      shortheader1("Blade Loading Charts");
!    }
COMMENT:Blade Loading Charts
  Comment Text = \
  <p>Note:  Blade loading charts are not supported for blades that are defined by multiple regions.</p>
END
!    return;
!  }

!  my $spanValue = $spanFraction*100;
!  my $chartName = "$name Span $spanValue";
!  my $chartTitle = "$name at ${spanValue}% Span";
!  my $chartLine = "$chartName Line";
!  my $chartLineName = "${spanValue}% Span";
!  my $chartXVariable = 'Streamwise (0-1)';
!  my $chartYVariable = $varName;
!  my $chartXLabel = 'Streamwise (0-1)';
!  my $chartYLabel = "$varName <units>";
!  my $bladeLoadingSurface = "$chartName Surface";
!  my $bladeLoadingLine = "$chartName Polyline";

!  if ( defined($TURBO_REPORT_DEBUG) && $TURBO_REPORT_DEBUG > 1 )
!  {
!    print "spanValue = $spanValue\n";
!    print "chartName = $chartName\n";
!    print "chartTitle = $chartTitle\n";
!    print "chartLine = $chartLine\n";
!    print "chartLineName = $chartLineName\n";
!    print "chartXVariable = $chartXVariable\n";
!    print "chartYVariable = $chartYVariable\n";
!    print "chartXLabel = $chartXLabel\n";
!    print "chartYLabel = $chartYLabel\n";
!    print "bladeLoadingSurface = $bladeLoadingSurface\n";
!    print "bladeLoadingLine = $bladeLoadingLine\n";
!  }

!  hiddenSpanwiseSurface( $bladeLoadingSurface, $spanFraction );

POLYLINE:$bladeLoadingLine
  Boundary List = $regionBlade
  Domain List = $domain
  Location = $bladeLoadingSurface
  Option = Boundary Intersection
END
>hide $bladeLoadingLine

!  my $min;
!  my $max;
!  ($min, $max) = smartLegendChart( $varName, $bladeLoadingLine);

CHART:$chartName
  Chart Axes = Both
  Chart Axes Font = Tahoma, 10, False, False
  Chart Axes Titles Font = Tahoma, 10, True, False
  Chart Grid Line Width = 1
  Chart Horizontal Grid = On
  Chart Legend = Off
  Chart Legend Font = Tahoma, 8, False, False
  Chart Legend Position = Bottom
  Chart Line Width = 2
  Chart Minor Grid = Off
  Chart Minor Grid Line Width = 1
  Chart Symbol Size = 2
  Chart Text Colour = White
  Chart Title = $chartTitle
  Chart Title Font = Tahoma, 12, True, False
  Chart Type = XY
  Chart Vertical Grid = On
  Chart Viewport Colour = Yellow
  Chart X Axis Label = $chartXLabel
  Chart Y Axis Label = $chartYLabel
  Max X = 1.0
  Min X = 0.0
  Max Y = $max
  Min Y = $min
  Use Data For Axis Labels = Off
  X Axis Automatic Range = Off
  X Axis Inverted = Off
  X Axis Logarithmic Scaling = Off
  Y Axis Automatic Range = Off
  Y Axis Inverted = Off
  Y Axis Logarithmic Scaling = Off
  CHART LINE:$chartLine
    Auto Chart Line Colour = Off
    Chart Line Colour = 0, 0, 1
    Chart Line Style = Automatic
    Chart Line Type = Regular
    Chart Line Visibility = On
    Chart Symbol Colour = 0, 0, 1
    Chart Symbol Style = None
    Chart X Variable = $chartXVariable
    Chart Y Variable = $chartYVariable
    Line Name = $chartLineName
    Location = $bladeLoadingLine
  END
  OBJECT REPORT OPTIONS:
    Report Caption = $chartTitle
  END
END
!  return;
!}


#### streamwiseTurboLine
!sub streamwiseTurboLine
!{
!  my ($lineName, $varName, $avgType, $npts) = @_;
!  if ( defined($TURBO_REPORT_DEBUG) && $TURBO_REPORT_DEBUG > 0 )
!  {
!    print "streamwiseTurboLine( $lineName, $varName, $avgType, $npts )\n";
!  }

!  my $mode;
!  my $returnVar;
!  if ($avgType eq "mass")
!  {
!    $mode = "Mass";
!    $returnVar = "$varName MCA on $lineName";
!  }
!  else
!  {
!    $mode = "Area";
!    $returnVar = "$varName ACA on $lineName";
!  }

TURBO LINE:$lineName
  Circumferential Average Mode = $mode
  Colour Mode = Variable
  Colour Scale = Linear
  Colour Variable = $varName
  Colour Variable Boundary Values = Conservative
  Include Boundary Points = On
  Invert Line Bound = Off
  Line Bound = None
  Option = Inlet to Outlet
  Point Distribution Method = Equal Distance
  Span = 0.5
  Streamwise Points = $npts
  Theta = 0 [degree]
  Turbo Domain List = $domain
  Turbo Line Mode = Streamwise Location
END
>hide $lineName
!  return $returnVar; 
!}


#### streamwiseChart
!sub streamwiseChart
!{
!  my ($chartName, $npts, @lineInfo) = @_;
!  if ( defined($TURBO_REPORT_DEBUG) && $TURBO_REPORT_DEBUG > 0 )
!  {
!    print "streamwiseChart( $chartName, $npts, @lineInfo )\n";
!  }

!  my @symbols = ( "Ellipse", "Rectangle", "Diamond", "Triangle", "Cross" );
!  my @colors = ( "0, 0, 1", "1, 0, 0", "0, 0.7, 0", "1, 0.62, 0", "0.67, 0, 1" );

!  my $chartXVariable = "Streamwise Location";
!  my @chartYLabels;

!  my $index = 0;
!  my $maxMax = -1E20;
!  my $minMin = 1E20; 
!  while ( @lineInfo > 2 )
!  {
!    my $varName = shift( @lineInfo );
!    my $varShortName = shift( @lineInfo );
!    my $avgType = shift( @lineInfo );
!    $chartYLabels[$index] = $varShortName;
!    my $chartLine = "Streamwise Plot of $varShortName";
!    my $turboLine = "$chartLine Line";
!    my $turboVarName = streamwiseTurboLine($turboLine, $varName, $avgType, $npts);
!    my $symbol = $symbols[$index % @symbols];
!    my $color = $colors[$index % @colors];
!    my $min;
!    my $max;
!    ($min, $max) = smartLegendChart( $turboVarName, $turboLine);
!    $maxMax = ($maxMax < $max) ? $max : $maxMax;
!    $minMin = ($minMin > $min) ? $min : $minMin;

CHART:$chartName
  CHART LINE:$chartLine
    Auto Chart Line Colour = Off
    Chart Line Colour = $color
    Chart Line Style = Solid
    Chart Line Type = Regular
    Chart Line Visibility = On
    Chart Symbol Colour = $color
    Chart Symbol Style = $symbol
    Chart X Variable = $chartXVariable
    Chart Y Variable = $turboVarName
    Line Name = $varShortName
    Location = $turboLine
  END
END
!    $index++;
!  }

!  my $chartXLabel = $chartXVariable . ' <units>';
!  my $chartYLabel = join( ', ', @chartYLabels ) . ' <units>'; 

!  my $legendVis;
!  if ( $index > 1)
!  {
!    $legendVis = 'On';
!  }
!  else
!  {
!    $legendVis = 'Off';
!  }

CHART:$chartName
  Chart Axes = Both
  Chart Axes Font = Tahoma, 10, False, False
  Chart Axes Titles Font = Tahoma, 10, True, False
  Chart Grid Line Width = 1
  Chart Horizontal Grid = On
  Chart Legend = $legendVis
  Chart Legend Font = Tahoma, 8, False, False
  Chart Legend Position = Bottom
  Chart Line Width = 2
  Chart Minor Grid = Off
  Chart Minor Grid Line Width = 1
  Chart Symbol Size = 4
  Chart Text Colour = White
  Chart Title = $chartName
  Chart Title Font = Tahoma, 12, True, False
  Chart Type = XY
  Chart Vertical Grid = On
  Chart Viewport Colour = Yellow
  Chart X Axis Label = $chartXLabel
  Chart Y Axis Label = $chartYLabel
  Min X = $locStreamMin
  Max X = $locStreamMax
  Min Y = $minMin
  Max Y = $maxMax
  Use Data For Axis Labels = Off
  X Axis Automatic Range = Off
  Y Axis Automatic Range = Off
  OBJECT REPORT OPTIONS:
    Report Caption = $chartName
  END
END
!}


#### spanwiseTurboLine
!sub spanwiseTurboLine
!{
!  my ($lineName, $varName, $streamLoc, $avgType, $npts) = @_;
!  if ( defined($TURBO_REPORT_DEBUG) && $TURBO_REPORT_DEBUG > 0 )
!  {
!    print "spanwiseTurboLine( $lineName, $varName, $streamLoc, $avgType, $npts )\n";
!  }

!  my $mode;
!  my $returnVar;
!  if ($avgType eq "mass")
!  {
!    $mode = "Mass";
!    $returnVar = "$varName MCA on $lineName";
!  }
!  else
!  {
!    $mode = "Area";
!    $returnVar = "$varName ACA on $lineName";
!  }

TURBO LINE:$lineName
  Circumferential Average Mode = $mode
  Colour Mode = Variable
  Colour Scale = Linear
  Colour Variable = $varName
  Colour Variable Boundary Values = Conservative
  Include Boundary Points = On
  Invert Line Bound = Off
  Line Bound = None
  Option = Hub to Shroud
  Point Distribution Method = Equal Distance
  Span Max = 1.0
  Span Min = 0.0
  Span Points = $npts
  Streamwise Location = $streamLoc
  Theta = 0 [degree]
  Turbo Domain List = $domain
  Turbo Line Mode = Blade Aligned
END
>hide $lineName
!  return $returnVar; 
!}


#### spanwiseChart
!sub spanwiseChart
!{
!  my ($name, $locName, $streamFraction, $npts, @lineInfo) = @_;
!  if ( defined($TURBO_REPORT_DEBUG) && $TURBO_REPORT_DEBUG > 0 )
!  {
!    print "spanwiseChart( $name, $locName, $streamFraction, $npts, @lineInfo )\n";
!  }

!  my @symbols = ( "Ellipse", "Rectangle", "Diamond", "Triangle", "Cross" );
!  my @colors = ( "0, 0, 1", "1, 0, 0", "0, 0.7, 0", "1, 0.62, 0", "0.67, 0, 1" );

!  my $chartName = $name . " " . $locName;
!  my $chartXVariable = "Span Normalized";
!  my @chartYLabels;

!  my $index = 0;
!  my $maxMax = -1E20;
!  my $minMin = 1E20; 
!  while ( @lineInfo > 2 )
!  {
!    my $varName = shift( @lineInfo );
!    my $varShortName = shift( @lineInfo );
!    my $avgType = shift( @lineInfo );
!    $chartYLabels[$index] = $varShortName;
!    my $chartLine = "Spanwise Plot of $varShortName $locName";
!    my $turboLine = "$chartLine Line";
!    my $turboVarName = spanwiseTurboLine($turboLine, $varName, $streamFraction, $avgType, $npts);
!    my $symbol = $symbols[$index % @symbols];
!    my $color = $colors[$index % @colors];
!    my $min;
!    my $max;
!    ($min, $max) = smartLegendChart( $turboVarName, $turboLine);
!    $maxMax = ($maxMax < $max) ? $max : $maxMax;
!    $minMin = ($minMin > $min) ? $min : $minMin;

CHART:$chartName
  CHART LINE:$chartLine
    Auto Chart Line Colour = Off
    Chart Line Colour = $color
    Chart Line Style = Solid
    Chart Line Type = Regular
    Chart Line Visibility = On
    Chart Symbol Colour = $color
    Chart Symbol Style = $symbol
    Chart X Variable = $chartXVariable
    Chart Y Variable = $turboVarName
    Line Name = $varShortName
    Location = $turboLine
  END
END
!    $index++;
!  }

!  my $chartXLabel = $chartXVariable . ' <units>';
!  my $chartYLabel = join( ', ', @chartYLabels ) . ' <units>'; 

!  my $legendVis;
!  if ( $index > 1)
!  {
!    $legendVis = 'On';
!  }
!  else
!  {
!    $legendVis = 'Off';
!  }

CHART:$chartName
  Chart Axes = Both
  Chart Axes Font = Tahoma, 10, False, False
  Chart Axes Titles Font = Tahoma, 10, True, False
  Chart Grid Line Width = 1
  Chart Horizontal Grid = On
  Chart Legend = $legendVis
  Chart Legend Font = Tahoma, 8, False, False
  Chart Legend Position = Bottom
  Chart Line Width = 2
  Chart Minor Grid = Off
  Chart Minor Grid Line Width = 1
  Chart Symbol Size = 4
  Chart Text Colour = White
  Chart Title = $chartName
  Chart Title Font = Tahoma, 12, True, False
  Chart Type = XY
  Chart Vertical Grid = On
  Chart Viewport Colour = Yellow
  Chart X Axis Label = $chartXLabel
  Chart Y Axis Label = $chartYLabel
  Min X = 0
  Max X = 1.0
  Min Y = $minMin
  Max Y = $maxMax
  Use Data For Axis Labels = Off
  X Axis Automatic Range = Off
  Y Axis Automatic Range = Off
  OBJECT REPORT OPTIONS:
    Report Caption = $chartName
  END
END
!}


#### bladeGeometryPlots
!sub bladeGeometryPlots
!{
SURFACE GROUP:Blade Surface Group
  Apply Instancing Transform = On
  Colour = 0, 0.666667, 1
  Colour Mode = Constant
  Domain List = $domain
  Draw Faces = On
  Draw Lines = Off
  Instancing Transform = All Blades Transform
  Lighting = On
  Location List = $regionBlade
  Specular Lighting = On
  Surface Drawing = Smooth Shading
  Transparency = 0
END
SURFACE GROUP:Hub Surface Group
  Apply Instancing Transform = On
  Colour = 0.333333, 0.333333, 0.498039
  Colour Mode = Constant
  Domain List = $domain
  Draw Faces = On
  Draw Lines = Off
  Instancing Transform = All Blades Transform
  Lighting = On
  Location List = $regionHub
  Specular Lighting = On
  Surface Drawing = Smooth Shading
  Transparency = 0
END
SURFACE GROUP:Shroud Surface Group
  Apply Instancing Transform = On
  Colour = 0.75, 0.75, 0.75
  Colour Mode = Constant
  Domain List = $domain
  Draw Faces = On
  Draw Lines = Off
  Instancing Transform = All Blades Transform
  Lighting = On
  Location List = $regionShroud
  Specular Lighting = On
  Surface Drawing = Smooth Shading
  Transparency = 0.8
END

# Isometric 3D View

VIEW:Blade Geometry Isometric 3D View
  Axis Visibility = On
  Auto Center = false
  Axis Visibility = true
  Border Visibility = true
  Camera Mode = User Specified
  Coord Transform = Cartesian
  Local Object List = /SURFACE GROUP:Blade Surface Group, \
  /SURFACE GROUP:Hub Surface Group, /SURFACE GROUP:Shroud Surface Group
  Object Visibility List = /SURFACE GROUP:Blade Surface Group, \
  /SURFACE GROUP:Hub Surface Group, /SURFACE GROUP:Shroud Surface Group
  Ruler Visibility = On
#  Standard View = Isometric Z
  CAMERA:
    Option = Pivot Point and Quaternion
    Pivot Point = -0.00122057, 0.00477216, -0.050858
    Scale = 4.89529
    Pan = 0, 0
    Rotation Quaternion = -0.612373, 0.612373, -0.353554, -0.353553
    Send To Viewer = False
  END
  OBJECT REPORT OPTIONS:
    Report Caption = Isometric 3D View of the Blade, Hub and Shroud
  END

END
!cameraViewVector('Blade Geometry Isometric 3D View', @rotAxis , 0,0,0, 1, -0.785);
>setViewportView cmd=set, view=/VIEW:Blade Geometry Isometric 3D View, viewport=1
>centerview 1

# Meridional View

TURBO SURFACE:Blade Geometry Meridional Wireframe
  Turbo Domain List = $domain
  Option = Constant Theta
  Surface Type = Sample
  Span Points = 15
  Streamwise Points = 50
  Colour Mode = Constant
  Circumferential Average Mode = None
  Draw Faces = Off
  Draw Lines = On
  Line Colour = 0, 0, 0
  Line Colour Mode = Default
  Line Width = 2
  Render Edge Angle = 30 [degree]
END
VIEW:Blade Geometry Meridional View
  Axis Visibility = On
  Auto Center = false
  Axis Visibility = true
  Border Visibility = true
  Camera Mode = User Specified
  Coord Transform = 2D Meridional
  Local Object List = /SURFACE GROUP:Blade Surface Group, \
  /SURFACE GROUP:Hub Surface Group, /SURFACE GROUP:Shroud Surface Group, \
  /TURBO SURFACE:Blade Geometry Meridional Wireframe
  Object Visibility List = /SURFACE GROUP:Blade Surface Group, \
  /SURFACE GROUP:Hub Surface Group, /SURFACE GROUP:Shroud Surface Group, \
  /TURBO SURFACE:Blade Geometry Meridional Wireframe
  Ruler Visibility = On
  Standard View = Isometric Z
  CAMERA:
    Option = Pivot Point and Quaternion
    Pan = 0, 0
    Pivot Point = 0, 0, -0.0715793
    Rotation Quaternion = -0.836417, 0.346455, -0.162529, -0.39238
    Scale = 3.12441
    Send To Viewer = False
  END
  OBJECT REPORT OPTIONS:
    Report Caption = Meridional View of the Blade, Hub and Shroud
  END
END
>setViewportView cmd=set, view=/VIEW:Blade Geometry Meridional View, viewport=1
>centerview 1
!}


#### bladeMeshPlot
!sub bladeMeshPlot
!{
!  my ( $spanFraction ) = @_;
!  if ( defined($TURBO_REPORT_DEBUG) && $TURBO_REPORT_DEBUG > 0 )
!  {
!    print "bladeMeshPlot( $spanFraction )\n";
!  }

!  my $spanValue = $spanFraction*100;
!  my $volumeName = "Mesh Elements at Span $spanValue";
!  my $turboSurface = "$volumeName Surface";
!  my $meshView = "$volumeName View";
!  my $caption = "Mesh Elements at ${spanValue}% Span";
!  my $transform;
!  my $copies;
!  if ( $numCopies > 1 )
!  {
!    $transform = 'Two Blades Transform';
!    $copies = 2;
!  }
!  else
!  {
!    $transform = 'All Blades Transform';
!    $copies = 1;
!  }


!  hiddenSpanwiseSurface($turboSurface, $spanFraction);

VOLUME:$volumeName
  Apply Instancing Transform = On
  Apply Texture = Off
  Blend Texture = On
  Colour = 0, 0.666667, 1
  Colour Mode = Constant
  Domain List = $domain
  Draw Faces = On
  Draw Lines = On
  Element Type List = Tet, Pyramid, Wedge, Hex, Polyhedra
  Inclusive = Off
  Instancing Transform = $transform
  Lighting = On
  Line Colour = 0, 0, 0
  Line Colour Mode = Default
  Line Width = 1
  Location List = $turboSurface
  Option = From Surface
  Point = 0 [mm], 0 [mm], 0 [mm]
  Radius = 1 [m]
  Range = Global
  Render Edge Angle = 0 [degree]
  Specular Lighting = On
  Surface Drawing = Flat Shading
  Transparency = 0.0
  Volume Intersection Mode = Intersection
END
VIEW:$meshView
  Angular Coord Shift = 0.0 [degree]
  Auto Center = false
  Axis Visibility = true
  Border Visibility = false
  Camera Mode = User Specified
  Clip Scene = false
  Coord Transform = Cartesian
  Local Object List = /TURBO SURFACE:$turboSurface, /VOLUME:$volumeName
  Object Visibility List = /VOLUME:$volumeName
  Projection = Orthographic
  Ruler Visibility = false
  CAMERA:
    Option = Pivot Point and Quaternion
    Pivot Point = -0.00122057, 0.00477216, -0.050858
    Scale = 4.89529
    Pan = 0, 0
    Rotation Quaternion = -0.612373, 0.612373, -0.353554, -0.353553
    Send To Viewer = False
  END
  OBJECT REPORT OPTIONS:
    Report Caption = $caption
  END
END
!  cameraViewRegion($meshView, $turboSurface, $copies, 1, 0);
>setViewportView cmd=set, view=/VIEW:$meshView, viewport=1
>centerview 1
!  return($volumeName);
!}


#### bladetobladeContourPlot
!sub bladetobladeContourPlot
!{
!  my ($varName, $varShortName, $spanFraction, $numContours) = @_;
!  if ( defined($TURBO_REPORT_DEBUG) && $TURBO_REPORT_DEBUG > 0 )
!  {
!    print "bladetobladeContourPlot( $varName, $varShortName, $spanFraction, $numContours )\n";
!  }

!  my $spanValue = $spanFraction*100;
!  my $contourName = "Contour of $varShortName Span $spanValue";
!  my $turboSurface = "$contourName Surface";
!  my $contourView = "$contourName View";
!  my $legendName = "$contourName Legend";
!  my $caption = "Contour of $varShortName at ${spanValue}% Span";
!  my $transform;
!  if ( $numCopies > 2 )
!  {
!    $transform = 'Three Blades Transform';
!  }
!  else
!  {
!    $transform = 'All Blades Transform';
!  }

!  hiddenSpanwiseSurface( $turboSurface, $spanFraction );

!  my $min;
!  my $max;
!  my $levels;
!  my $format;
!  ($min, $max, $levels, $format) = smartLegendPlot( $varName, $turboSurface, $numContours );

CONTOUR:$contourName
  Location List = $turboSurface
  Colour Variable = $varName
  Colour Variable Boundary Values = Hybrid
  Contour Range = User Specified
  Instancing Transform = $transform
  Min = $min
  Max = $max
  Number of Contours = $levels
  Value List = 0.0, 1.0
  Constant Contour Colour = On
  Line Colour = 0, 0, 0
  Line Colour Mode = User Specified
  Line Width = 1
  Lighting = Off
END
LEGEND:$legendName
  Legend Title Mode = User Specified
  Legend Title = $varShortName
  Legend X Justification = Left
  Legend Plot = $contourName
  Legend Format = $format
END
VIEW:$contourView
  Angular Coord Shift = 0.0 [degree]
  Auto Center = false
  Axis Visibility = true
  Border Visibility = false
  Camera Mode = User Specified
  Clip Scene = false
  Coord Transform = 2D Blade-to-blade
  Local Object List = /CONTOUR:$contourName, /LEGEND:$legendName, /TURBO SURFACE:$turboSurface
  Object Visibility List = /CONTOUR:$contourName, /LEGEND:$legendName
  Projection = Orthographic
  Ruler Visibility = false
  Standard View = Isometric Y
  CAMERA:
    Option = Pivot Point and Quaternion
    Pivot Point = 3.04962, 8.07173, 0.428172
    Scale = 0.126147
    Pan = 0, 0
    Rotation Quaternion = 0, 0, -0.707107, 0.707107
    Send To Viewer = False
    Rotation = -90, 0, 0
  END
  OBJECT REPORT OPTIONS:
    Report Caption = $caption
  END
END
>setViewportView cmd=set, view=/VIEW:$contourView, viewport=1
>centerview 1
!  return($contourName);
!}


#### bladetobladeVectorPlot
!sub bladetobladeVectorPlot
!{
!  my ($spanFraction) = @_;
!  if ( defined($TURBO_REPORT_DEBUG) && $TURBO_REPORT_DEBUG > 0 )
!  {
!    print "bladetobladeVectorPlot( $spanFraction )\n";
!  }

!  my $spanOffset = 0.002;
!  my $spanVecSurf = $spanFraction + $spanOffset;
!  if ( $spanFraction > 1 )
!  {
!    $spanFraction = 0.999;
!    $spanVecSurf = 1;
!  }
!  elsif ( $spanFraction < 0 )
!  {
!    $spanFraction = 0;
!    $spanVecSurf = $spanOffset;
!  }
!  my $spanValue = $spanFraction*100;
!  my $vectorName = "Velocity Vectors Span $spanValue";
!  my $streamName = "Velocity Streamlines Span $spanValue";
!  my $cloudName = "Velocity Streamlines Span $spanValue Point Cloud";
!  my $turboSurfaceCol = "Velocity Color Span $spanValue Surface";
!  my $turboSurfaceVec = "$vectorName Surface";
!  my $vectorView = "$vectorName View";
!  my $legendName = "$vectorName Legend";
!  my $caption = "Velocity Vectors at ${spanValue}% Span";
!  my $transform;
!  if ( $numCopies > 2 )
!  {
!    $transform = 'Three Blades Transform';
!  }
!  else
!  {
!    $transform = 'All Blades Transform';
!  }

TURBO SURFACE:$turboSurfaceCol
  Colour Map = Rainbow
  Colour Mode = Variable
  Colour Scale = Linear
  Colour Variable = Velocity
  Colour Variable Boundary Values = Hybrid
  Draw Faces = On
  Draw Lines = Off
  Instancing Transform = $transform
  Lighting = Off
  Option = Constant Span
  Range = Local
  Span = $spanFraction
  Specular Lighting = Off
  Surface Drawing = Smooth Shading
  Surface Type = Slice
  Turbo Domain List = $domain
  Apply Instancing Transform = On
END
TURBO SURFACE:$turboSurfaceVec
  Colour Mode = Constant
  Draw Faces = Off
  Draw Lines = Off
  Lighting = Off
  Option = Constant Span
  Range = Local
  Span = $spanVecSurf
  Specular Lighting = Off
  Surface Drawing = Smooth Shading
  Surface Type = Slice
  Turbo Domain List = $domain
  Apply Instancing Transform = Off
END

# Get legend values
!  my $min;
!  my $max;
!  my $levels;
!  my $format;
!  ($min, $max, $levels, $format) = smartLegendPlot( 'Velocity', $turboSurfaceCol, 20 );

# Compute streamline timescale limit
!  my $timeScale;
!  my $timeUnits;
!  ($timeScale, $timeUnits) = evaluate( "0.1 * maxVal(M Length Local)\@$turboSurfaceCol / ave(Velocity)\@$turboSurfaceCol" );
!  $timeScale = "$timeScale [$timeUnits]";

TURBO SURFACE:$turboSurfaceCol
  Range = User Specified
  Min = $min
  Max = $max
END

POINT CLOUD:$cloudName
  Apply Instancing Transform = Off
  Colour = 0, 0, 0
  Colour Mode = Constant
  Domain List = $domain
  Draw Faces = Off
  Draw Lines = Off
  Lighting = Off
  Line Colour = 0, 0, 0
  Line Colour Mode = Default
  Line Width = 2
  Location List = $turboSurfaceVec
  Locator Sampling Method = Equally Spaced
  Number of Samples = 75
  Random Seed = 1
  Range = Global
  Specular Lighting = Off
END
VECTOR:$vectorName
  Apply Instancing Transform = On
  Colour = 0, 0, 0
  Colour Mode = Constant
  Domain List = $domain
  Draw Faces = On
  Draw Lines = Off
  Instancing Transform = $transform
  Lighting = Off
  Location List = $cloudName
  Locator Sampling Method = Vertex
  Normalized = On
  Projection Type = Tangential
  Range = Local
  Reduction Factor = 1.0
  Reduction or Max Number = Reduction
  Specular Lighting = Off
  Surface Drawing = Smooth Shading
  Symbol = Arrowhead3D
  Symbol Size = 4
  Transparency = 0.5
  Variable = Velocity
  Variable Boundary Values = Hybrid
END
STREAMLINE:$streamName
  Add Sample Vertex Normals = Off
  Apply Instancing Transform = On
  Colour = 0, 0, 0
  Colour Mode = Constant
  Cross Periodics = On
  Domain List = $domain
  Draw Faces = Off
  Draw Lines = Off
  Draw Streams = On
  Draw Symbols = Off
  Grid Tolerance = 0.01
  Instancing Transform = $transform
  Lighting = Off
  Line Colour = 0, 0, 0
  Line Width = 1
  Location List = $turboSurfaceVec
  Reduction Factor = 1.0
  Reduction or Max Number = Reduction
  Seed Point Type = Locations
  Seed Location List = $cloudName
  Simplify Geometry = On
  Specular Lighting = Off
  Stream Drawing Mode = Line
  Stream Initial Direction = 0 , 1 , 0
  Stream Size = 1.0
  Streamline Maximum Periods = 20
  Streamline Maximum Segments = 10000
  Streamline Maximum Time = $timeScale
  Streamline Type = Surface Streamline
  Streamline Width = 2
  Surface Streamline Direction = Backward
  Symbol Size = 1.0
  Symbol Start Time = 10 [s]
  Symbol Stop Time = -10 [s]
  Symbol Time Interval = 1 [s]
  Tolerance Mode = Grid Relative
  Transparency = 0.0
  Variable = Velocity
  Variable Boundary Values = Conservative
END
LEGEND:$legendName
  Legend Title Mode = User Specified
  Legend Title = Velocity
  Legend X Justification = Left
  Legend Plot = $turboSurfaceCol
  Legend Format = $format
  Legend Ticks = $levels
END
VIEW:$vectorView
  Angular Coord Shift = 0.0 [degree]
  Auto Center = false
  Axis Visibility = true
  Border Visibility = false
  Camera Mode = User Specified
  Clip Scene = false
  Coord Transform = 2D Blade-to-blade
  Highlight Type = Surface Mesh
  Light Angle = 50, 110
  Local Object List = /TURBO SURFACE:$turboSurfaceCol, /TURBO SURFACE:$turboSurfaceVec, /POINT CLOUD:$cloudName, /VECTOR:$vectorName, /STREAMLINE:$streamName, /LEGEND:$legendName
  Object Visibility List = /TURBO SURFACE:$turboSurfaceCol, /VECTOR:$vectorName, /STREAMLINE:$streamName, /LEGEND:$legendName
  Projection = Orthographic
  Ruler Visibility = true
  Standard View = Isometric Y
  CAMERA:
    Option = Pivot Point and Quaternion
    Pivot Point = 3.04962, 8.07173, 0.428172
    Scale = 0.126147
    Pan = 0, 0
    Rotation Quaternion = 0, 0, -0.707107, 0.707107
    Send To Viewer = False
    Rotation = -90, 0, 0
  END
  OBJECT REPORT OPTIONS:
    Report Caption = $caption
  END
END
>setViewportView cmd=set, view=/VIEW:$vectorView, viewport=1
>centerview 1
!  return($vectorName);
!}


#### meridionalContourPlot
!sub meridionalContourPlot
!{
!  my ($varName, $varShortName, $numContours) = @_;
!  if ( defined($TURBO_REPORT_DEBUG) && $TURBO_REPORT_DEBUG > 0 )
!  {
!    print "meridionalContourPlot( $varName, $varShortName, $numContours )\n";
!  }

!  my $turboSurface = "Meridional $varShortName Surface";
!  my $turboVarName = "$varName ACA on $turboSurface";
!  my $contourName = "Contour of $varShortName on Meridional Surface";
!  my $contourView = "$contourName View";
!  my $legendName = "$contourName Legend";
!  my $turboLineLE = "Meridional $varShortName LE Line";
!  my $turboLineTE = "Meridional $varShortName TE Line";
!  my $caption = "Contour of Mass Averaged $varShortName on Meridional Surface";

TURBO SURFACE:$turboSurface
  Apply Instancing Transform = Off
  Turbo Domain List = $domain
  Option = Constant Theta
  Surface Type = Sample
  Span Points = 15
  Streamwise Points = 50
  Colour Mode = Variable
  Circumferential Average Mode = Area
  Maximum Number of Sampling Points = 20
  Colour Variable = $varName
  Draw Faces = Off
  Render Edge Angle = 30 [degree]
  Draw Lines = On
END

!  my $min;
!  my $max;
!  my $levels;
!  my $format;
!  ($min, $max, $levels, $format) = smartLegendPlot( $turboVarName, $turboSurface, $numContours );

CONTOUR:$contourName
  Apply Instancing Transform = Off
  Location List = $turboSurface
  Colour Variable = $turboVarName
  Colour Variable Boundary Values = Hybrid
  Contour Range = User Specified
  Min = $min
  Max = $max
  Number of Contours = $levels
  Value List = 0.0, 1.0
  Constant Contour Colour = On
  Line Colour = 0, 0, 0
  Line Colour Mode = User Specified
  Line Width = 1
  Lighting = Off
END
LEGEND:$legendName
  Legend Title Mode = User Specified
  Legend Title = $varShortName
  Legend X Justification = Left
  Legend Plot = $contourName
  Legend Format = $format
END
TURBO LINE:$turboLineLE
  Apply Instancing Transform = Off
  Colour = 0.6, 0.6, 0.6
  Colour Mode = Constant
  Line Width = 2
  Option = Hub to Shroud
  Span Points = 20
  Streamwise Location = $locStreamLE
  Theta = 0 [degree]
  Turbo Domain List = $domain
  Turbo Line Mode = Blade Aligned
END
TURBO LINE:$turboLineTE
  Apply Instancing Transform = Off
  Colour = 0.6, 0.6, 0.6
  Colour Mode = Constant
  Line Width = 2
  Option = Hub to Shroud
  Span Points = 20
  Streamwise Location = $locStreamTE
  Theta = 0 [degree]
  Turbo Domain List = $domain
  Turbo Line Mode = Blade Aligned
END
VIEW:$contourView
  Auto Center = false
  Axis Visibility = true
  Border Visibility = false
  Coord Transform = 2D Meridional
  Local Object List = /CONTOUR:$contourName, /LEGEND:$legendName, \
  /TURBO SURFACE:$turboSurface, /TURBO LINE:$turboLineLE, /TURBO LINE:$turboLineTE
  Object Visibility List = /CONTOUR:$contourName, /LEGEND:$legendName, \
  /TURBO LINE:$turboLineLE, /TURBO LINE:$turboLineTE
  Projection = Orthographic
  Ruler Visibility = false
  Standard View = Isometric Y
  OBJECT REPORT OPTIONS:
    Report Caption = $caption
  END
END
>setViewportView cmd=set, view=/VIEW:$contourView, viewport=1
>centerview 1
!  return($contourName);
!}


#### meridionalVectorPlot
!sub meridionalVectorPlot
!{
!  if ( defined($TURBO_REPORT_DEBUG) && $TURBO_REPORT_DEBUG > 0 )
!  {
!    print "meridionalVectorPlot( )\n";
!  }

!  my ($varName, $varShortName) = @_;
!  my $turboSurface = "Meridional $varShortName Surface";
!  my $turboVarName = "$varName ACA on $turboSurface";
!  my $vectorName = "Vector of $varShortName on Meridional Surface";
!  my $vectorView = "$vectorName View";
!  my $legendName = "$vectorName Legend";
!  my $turboLineLE = "Meridional $varShortName LE Line";
!  my $turboLineTE = "Meridional $varShortName TE Line";
!  my $caption = "Vector of Area Averaged $varShortName on Meridional Surface";

TURBO SURFACE:$turboSurface
  Apply Instancing Transform = Off
  Turbo Domain List = $domain
  Option = Constant Theta
  Surface Type = Sample
  Span Points = 15
  Streamwise Points = 50
  Colour Mode = Variable
  Colour Variable = $varName
  Range = Local
  Circumferential Average Mode = Area
  Draw Faces = On
  Draw Lines = On
  Render Edge Angle = 30 [degree]
  Lighting = Off
END

!  my $min;
!  my $max;
!  my $levels;
!  my $format;
!  ($min, $max, $levels, $format) = smartLegendPlot( $turboVarName, $turboSurface, 20 );

TURBO SURFACE:$turboSurface
  Range = User Specified
  Min = $min
  Max = $max
END

VECTOR:$vectorName
  Apply Instancing Transform = Off
  Colour = 0, 0, 0
  Colour Mode = Constant
  Domain List = $domain
  Draw Faces = On
  Draw Lines = Off
  Lighting = On
  Location List = $turboSurface
  Locator Sampling Method = Vertex
  Reduction or Max Number = Reduction
  Reduction Factor = 1.0
  Normalized = On
  Projection Type = Tangential
  Specular Lighting = Off
  Surface Drawing = Smooth Shading
  Symbol = Arrowhead3D
  Symbol Size = 1
  Transparency = 0.7
  Variable = $turboVarName
  Variable Boundary Values = Hybrid
END
LEGEND:$legendName
  Legend Title Mode = User Specified
  Legend Title = $varShortName
  Legend X Justification = Left
  Legend Plot = $turboSurface
  Legend Format = $format
  Legend Ticks = $levels
END
TURBO LINE:$turboLineLE
  Apply Instancing Transform = Off
  Colour = 0.6, 0.6, 0.6
  Colour Mode = Constant
  Line Width = 2
  Option = Hub to Shroud
  Span Points = 20
  Streamwise Location = $locStreamLE
  Theta = 0 [degree]
  Turbo Domain List = $domain
  Turbo Line Mode = Blade Aligned
END
TURBO LINE:$turboLineTE
  Apply Instancing Transform = Off
  Colour = 0.6, 0.6, 0.6
  Colour Mode = Constant
  Line Width = 2
  Option = Hub to Shroud
  Span Points = 20
  Streamwise Location = $locStreamTE
  Theta = 0 [degree]
  Turbo Domain List = $domain
  Turbo Line Mode = Blade Aligned
END
VIEW:$vectorView
  Auto Center = false
  Axis Visibility = true
  Border Visibility = false
  Coord Transform = 2D Meridional
  Local Object List = /VECTOR:$vectorName, /LEGEND:$legendName, \
  /TURBO SURFACE:$turboSurface, /TURBO LINE:$turboLineLE, /TURBO LINE:$turboLineTE
  Object Visibility List = /VECTOR:$vectorName, /LEGEND:$legendName, \
  /TURBO SURFACE:$turboSurface, /TURBO LINE:$turboLineLE, /TURBO LINE:$turboLineTE
  Projection = Orthographic
  Ruler Visibility = false
  Standard View = Isometric Y
  OBJECT REPORT OPTIONS:
    Report Caption = $caption
  END
END
>setViewportView cmd=set, view=/VIEW:$vectorView, viewport=1
>centerview 1
!  return($vectorName);
!}


#### circContourPlot
!sub circContourPlot
!{
!  my ($varName, $varShortName, $streamFraction, $locName, $numContours, $cameraSign) = @_;
!  if ( defined($TURBO_REPORT_DEBUG) && $TURBO_REPORT_DEBUG > 0 )
!  {
!    print "circContourPlot( $varName, $varShortName, $streamFraction, $locName, $numContours )\n";
!  }

!  my $turboSurface;
!  my $contourName;
!  my $caption;
!  if ( $locName =~ m"None" )
!  {
!    $contourName = "Contour of $varShortName Stream $streamFraction";
!    $turboSurface = "$contourName Surface";
!    $caption = "Contour of $varShortName at Streamwise Location $streamFraction";
!  }
!  else
!  {
!    $contourName = "Contour of $varShortName Stream $locName";
!    $turboSurface = "$contourName Surface";
!    $caption = "Contour of $varShortName at $locName";
!  }
!  my $bladesName = "$contourName Blades";
!  my $contourView = "$contourName View";
!  my $legendName = "$contourName Legend";
!  my $transform;
!  my $copies;
!  if ( $numCopies > 1 )
!  {
!    $transform = 'Two Blades Transform';
!    $copies = 2;
!  }
!  else
!  {
!    $transform = 'All Blades Transform';
!    $copies = 1;
!  }

!  hiddenStreamwiseSurface($turboSurface, $streamFraction);

!  my $min;
!  my $max;
!  my $levels;
!  my $format;
!  ($min, $max, $levels, $format) = smartLegendPlot( $varName, $turboSurface, $numContours );

CONTOUR:$contourName
  Location List = $turboSurface
  Colour Variable = $varName
  Colour Variable Boundary Values = Hybrid
  Contour Range = User Specified
  Max = $max
  Min = $min
  Number of Contours = $levels
  Instancing Transform = $transform
  Number of Contours = $levels
  Constant Contour Colour = On
  Line Colour = 0, 0, 0
  Line Colour Mode = User Specified
  Line Width = 1
  Lighting = Off
#  Specular Lighting = Off
END
LEGEND:$legendName
  Legend Title Mode = User Specified
  Legend Title = $varShortName
  Legend X Justification = Left
  Legend Plot = $contourName
  Legend Format = $format
END
SURFACE GROUP:$bladesName
  Apply Instancing Transform = On
  Colour = 0.4, 0.4, 0.4
  Colour Mode = Constant
  Domain List = $domain
  Draw Faces = On
  Draw Lines = Off
  Instancing Transform = $transform
  Lighting = On
  Location List = $regionBlade
  Specular Lighting = On
  Surface Drawing = Smooth Shading
  Transparency = 0.7
END
VIEW:$contourView
  Angular Coord Shift = 0.0 [degree]
  Auto Center = false
  Axis Visibility = true
  Border Visibility = false
  Camera Mode = User Specified
  Clip Scene = false
  Coord Transform = Cartesian
  Local Object List = /CONTOUR:$contourName, /LEGEND:$legendName, /TURBO SURFACE:$turboSurface, /SURFACE GROUP:$bladesName
  Object Visibility List = /CONTOUR:$contourName, /LEGEND:$legendName, /SURFACE GROUP:$bladesName
  Projection = Orthographic
  Ruler Visibility = false
  CAMERA:
    Option = Pivot Point and Quaternion
    Pivot Point = -0.00122057, 0.00477216, -0.050858
    Scale = 4.89529
    Pan = 0, 0
    Rotation Quaternion = -0.612373, 0.612373, -0.353554, -0.353553
    Send To Viewer = False
  END
  OBJECT REPORT OPTIONS:
    Report Caption = $caption
  END
END
!  cameraViewRegion($contourView, $turboSurface, $copies, $cameraSign, 0);
>setViewportView cmd=set, view=/VIEW:$contourView, viewport=1
>hide $bladesName, view=$contourView
>centerview 1
>show $bladesName, view=$contourView
!  return($contourName);
!}


#### circStreamPlot
!sub circStreamPlot
!{
!  my ($streamFraction, $locName) = @_;
!  if ( defined($TURBO_REPORT_DEBUG) && $TURBO_REPORT_DEBUG > 0 )
!  {
!    print "circStreamPlot( $streamFraction, $locName )\n";
!  }
!  my $streamName;
!  my $caption;
!  if ( $locName =~ m"None" )
!  {
!    $streamName = "Velocity Streamlines Stream $streamFraction";
!    $caption = "Velocity Streamlines at Streamwise Location $streamFraction";
!  }
!  else
!  {
!    $streamName = "Velocity Streamlines Stream $locName";
!    $caption = "Velocity Streamlines at $locName";
!  }
!  my $turboSurface = "$streamName Surface";
!  my $vectorView = "$streamName View";
!  my $legendName = "$streamName Legend";
!  my $bladesName = "$streamName Blades";
!  my $transform;
!  my $copies;
!  if ( $numCopies > 1 )
!  {
!    $transform = 'Two Blades Transform';
!    $copies = 2;
!  }
!  else
!  {
!    $transform = 'All Blades Transform';
!    $copies = 1;
!  }

!  hiddenStreamwiseSurface($turboSurface, $streamFraction);

# Compute streamline timescale limit
!  my $timeScale;
!  my $timeUnits;
!  ($timeScale, $timeUnits) = evaluate( "0.8 * areaAve(M Length Local)\@$turboSurface / ave(Velocity)\@$domain" );
!  my $timeInterval = 0.5 * $timeScale;
!  $timeScale = "$timeScale [$timeUnits]";
!  $timeInterval = "$timeInterval [$timeUnits]";
!  if ( defined($TURBO_REPORT_DEBUG) && $TURBO_REPORT_DEBUG > 1 )
!  {
!    print "timeScale = $timeScale\ntimeInterval = $timeInterval\n";
!  }

STREAMLINE:$streamName
  Apply Instancing Transform = On
  Colour Map = Rainbow
  Colour Mode = Variable
  Colour Scale = Linear
  Colour Variable = Velocity
  Colour Variable Boundary Values = Hybrid
  Cross Periodics = On
  Domain List = $domain
  Draw Faces = On
  Draw Lines = Off
  Draw Streams = On
  Draw Symbols = On
  Grid Tolerance = 0.01
  Instancing Transform = $transform
  Lighting = On
  Line Colour = 0, 0, 0
  Line Width = 1
  Location List = $turboSurface
  Locator Sampling Method = Equally Spaced
  Number of Samples = 30
  Number of Sides = 8
  Range = Local
  Sample Spacing = 0.1
  Sampling Aspect Ratio = 1
  Sampling Grid Angle = 0 [degree]
  Seed Point Type = Equally Spaced Samples
  Simplify Geometry = On
  Specular Lighting = On
  Stream Drawing Mode = Line
  Stream Initial Direction = 0 , 1 , 0
  Stream Size = 1.0
  Stream Symbol = Arrowhead3D
  Streamline Direction = Backward
  Streamline Maximum Periods = 20
  Streamline Maximum Segments = 10000
  Streamline Maximum Time = $timeScale
  Streamline Type = 3D Streamline
  Streamline Width = 2
  Surface Drawing = Smooth Shading
  Surface Streamline Direction = Forward and Backward
  Symbol Size = 2
  Symbol Start Time = 0 [s]
  Symbol Stop Time = -10 [s]
  Symbol Time Interval = $timeInterval
  Tolerance Mode = Grid Relative
  Transparency = 0.0
  Variable = Velocity
  Variable Boundary Values = Conservative
END

# Get legend values
!  my $min;
!  my $max;
!  my $levels;
!  my $format;
!  ($min, $max, $levels, $format) = smartLegendPlot( 'Velocity', $streamName, 20 );

STREAMLINE:$streamName
  Range = User Specified
  Min = $min
  Max = $max
END

LEGEND:$legendName
  Legend Title Mode = User Specified
  Legend Title = Velocity
  Legend X Justification = Left
  Legend Plot = $streamName
  Legend Format = $format
  Legend Ticks = $levels
END
SURFACE GROUP:$bladesName
  Apply Instancing Transform = On
  Colour = 0.4, 0.4, 0.4
  Colour Mode = Constant
  Domain List = $domain
  Draw Faces = On
  Draw Lines = Off
  Instancing Transform = $transform
  Lighting = On
  Location List = $regionBlade
  Specular Lighting = On
  Surface Drawing = Smooth Shading
  Transparency = 0.5
END
VIEW:$vectorView
  Angular Coord Shift = 0.0 [degree]
  Auto Center = false
  Axis Visibility = true
  Border Visibility = false
  Camera Mode = User Specified
  Clip Scene = false
  Coord Transform = Cartesian
  Local Object List = /TURBO SURFACE:$turboSurface, /STREAMLINE:$streamName, /LEGEND:$legendName, /SURFACE GROUP:$bladesName
  Object Visibility List = /STREAMLINE:$streamName, /LEGEND:$legendName, /SURFACE GROUP:$bladesName
  Projection = Orthographic
  Ruler Visibility = false
  CAMERA:
    Option = Pivot Point and Quaternion
    Pivot Point = -0.00122057, 0.00477216, -0.050858
    Scale = 4.89529
    Pan = 0, 0
    Rotation Quaternion = -0.612373, 0.612373, -0.353554, -0.353553
    Send To Viewer = False
  END
  OBJECT REPORT OPTIONS:
    Report Caption = $caption
  END
END
!  cameraViewRegion($vectorView, $turboSurface, $copies, 1, 0.35);
>setViewportView cmd=set, view=/VIEW:$vectorView, viewport=1
>centerview 1
!  return($vectorName);
!}


#### hiddenSpanwiseSurface
!sub hiddenSpanwiseSurface
!{
!  my ($name, $spanFraction) = @_;
!  if ( defined($TURBO_REPORT_DEBUG) && $TURBO_REPORT_DEBUG > 0 )
!  {
!    print "hiddenSpanwiseSurface( $name, $spanFraction )\n";
!  }

TURBO SURFACE:$name
  Draw Faces = Off
  Draw Lines = Off
  Option = Constant Span
  Span = $spanFraction
  Streamwise Max = $locStreamMax
  Streamwise Min = $locStreamMin
  Surface Type = Slice
  Turbo Domain List = $domain
END
>hide $name
!}


#### hiddenStreamwiseSurface
!sub hiddenStreamwiseSurface
!{
!  my ($name, $streamFraction) = @_;
!  if ( defined($TURBO_REPORT_DEBUG) && $TURBO_REPORT_DEBUG > 0 )
!  {
!    print "hiddenStreamwiseSurface( $name, $streamFraction )\n";
!  }

TURBO SURFACE:$name
  Option = Constant Blade Aligned
  Streamwise Location = $streamFraction
  Surface Type = Slice
  Draw Faces = Off
  Draw Lines = Off
END
>hide $name
!}


#### smartLegendPlot
!sub smartLegendPlot
!{
!  my ($varName, $locator, $maxLevels) = @_;

!  my $varMin;
!  my $varMax;
!  my $varUnits;
!  ($varMin, $varUnits) = evaluateInPreferred( "minVal($varName)\@$locator" );
!  ($varMax, $varUnits) = evaluateInPreferred( "maxVal($varName)\@$locator" );
!  my @returnVals = smartLegendRange( $varMin, $varMax, $maxLevels );
!  $returnVals[0] = $returnVals[0] . ' [' . $varUnits . ']';
!  $returnVals[1] = $returnVals[1] . ' [' . $varUnits . ']';

!  return @returnVals;
!}


#### smartLegendChart
!sub smartLegendChart
!{
!  my ($varName, $locator) = @_;

!  my $varMin;
!  my $varMax;
!  my $varUnits;
!  ($varMin, $varUnits) = evaluateInPreferred( "minVal($varName)\@$locator" );
!  ($varMax, $varUnits) = evaluateInPreferred( "maxVal($varName)\@$locator" );
!  my @returnVals = smartLegendRange( $varMin, $varMax, 10 );
!  my $min = $returnVals[0];
!  my $max = $returnVals[1];

!  return ($min, $max);
!}


#### smartLegendRange
!sub smartLegendRange
!{
!  my ($varMin, $varMax, $maxLevels) = @_;

!  # assume $varMax > $varMin
!  my $diff = $varMax - $varMin;
!  my $inc;
!  my $rndInc;
!  my $newMin;
!  my $newMax;
!  my $levels;

!  if ( $maxLevels < 2 )
!  {
!    $maxLevels = 2;
!  }
!  my $estLevels = $maxLevels;
!  do
!  {
!    $estLevels--;
!    $inc = $diff/$estLevels;
!    $rndInc = roundNum($inc, 0);

!    # compute lower level by rounding to nearest $rndInc value
!    $newMin = nearestInc($varMin, $rndInc);

!    # compute upper level
!    $levels = int(($varMax - $newMin)/$rndInc);
!    $newMax = $rndInc * $levels + $newMin;
!    if ($newMax < $varMax)
!    {
!      $levels++;
!      $newMax += $rndInc;
!    }
!  }
!  while ( $estLevels > 1 && $levels + 1 > $maxLevels );

!  # determine mode: fixed or scientific
!  my $format;
!  my $large1 = abs($newMax);
!  my $large2 = abs($newMin);
!  my $largeNum = ( ($large1 > $large2) ? $large1 : $large2 );
!  my $largeMag = numMag( $largeNum );
!  my $incMag = numMag($rndInc);

!  if ( $largeMag > 6 || $largeMag < -4 )
!  {
!    my $precision = $largeMag - $incMag;
!    if ( $precision < 2 )
!    {
!      $precision = 2;
!    }
!    my $width = $precision + 3;
!    $format = '%' . $width . '.' . $precision . 'e';
!  }
!  else
!  {
!    my $precision;
!    my $width;
!    if ( $incMag > 0 )
!    {
!      $precision = 0;
!      $width = $largeMag + 2;
!    }
!    else
!    {
!      $precision = abs( $incMag );
!      $width = $precision + 3;
!    }
!    $format = '%' . $width . '.' . $precision . 'f';
!  }

!  $levels++;  # Num of levels is number of increments + 1
!  return ($newMin, $newMax, $levels, $format);
!}


#### roundNum
!sub roundNum
!{
!  my ($initialNum, $scale) = @_;

!  my @wholeNums = ( 1, 2, 5, 10 );
#!  my @wholeNums = ( 1, 5, 10 );

!  my $sign = ($initialNum >=0) ? 1 : -1;
!  my $posNum = abs($initialNum);
!  my $mag = numMag($posNum);
!  my $pow = $mag - $scale + 1;
!  my $offset = 10**$pow * int($posNum * 10**(-$pow));
!  my $number = $posNum - $offset;
!  my $shift = numMag($number);
!  $number *= 10**(-$shift);

!  my $newNum;
!  my $minDiff = 1e20;
!  my $n = 0;
!  while ($n < @wholeNums)
!  {
!    my $diff = abs($number - $wholeNums[$n]);
!    if ($diff < $minDiff)
!    {
!      $minDiff = $diff;
!      $newNum = $wholeNums[$n];
!    }
!    $n++;
!  }
!  $newNum *= 10**($shift);
!  $newNum += $offset;
!  $newNum *= $sign;

!  return $newNum;
!}


#### nearestInc
!sub nearestInc
!{
!  my ($initialNum, $inc) = @_;

!  my $sign = ($initialNum >=0) ? 1 : -1;
!  my $posNum = abs($initialNum);
!  my $incMag = numMag($inc) + 1;
!  my $shift = int($posNum * 10**(-$incMag));
!  my $lowNum = 10**$incMag * $shift;
!  my $highNum = 10**$incMag * ($shift + 1);

!  my $n = 0;
!  my $newNum;
!  my $minDiff = 1e20;
!  my $testNum = $lowNum;
!  while ($testNum <= $posNum && $n < 10)
!  {
!    my $diff = abs($testNum - $posNum);
!    if ($diff < $minDiff)
!    {
!      $minDiff = $diff;
!      $newNum = $testNum;
!    }
!    $n++;
!    $testNum = $lowNum + $n*$inc;
!  }
!  if ($sign < 0)
!  {
!    if ($newNum < $posNum)
!    {
!      $newNum += $inc;
!    }
!    $newNum *= -1;
!  }
!  return $newNum;
!}


#### numMag
!sub numMag
!{
!  my ($number) = @_;

!  my $mag;
!  my $absNum = abs($number);
!  if ($absNum == 0)
!  {
!    $mag = 0;
!  }
!  else
!  {
!    $mag = int(log($absNum)/log(10));
!  }
!  if ($mag < 1 && $absNum < 1)
!  {
!      $mag--;
!  }
!  return $mag;
!}

#### cameraViewRegion
!sub cameraViewRegion
!{
!  my ($view, $region, $copies, $cameraSign, $cameraRotX) = @_;

# $cameraSign = 1 or -1 to reverse the orientation of the view
!  if ( abs($cameraSign) != 1 )
!  {
!    $cameraSign = 1;
!  }

#  Compute the camera pivot point based on the region centroid
!  my @pivotVec = ( 0, 0, 0);
!  ($pivotVec[0], $dummy) = evaluate( "areaAve(X)\@$region" );
!  ($pivotVec[1], $dummy) = evaluate( "areaAve(Y)\@$region" );
!  ($pivotVec[2], $dummy) = evaluate( "areaAve(Z)\@$region" );

#  Compute the camera orientation based on the aregion average normal direction
!  my @viewVec = ( 0, 0, 0);
!  ($viewVec[0], $dummy) = evaluate( "areaAve(Normal X)\@$region" );
!  ($viewVec[1], $dummy) = evaluate( "areaAve(Normal Y)\@$region" );
!  ($viewVec[2], $dummy) = evaluate( "areaAve(Normal Z)\@$region" );
!  $viewVec[0] *= -$cameraSign;
!  $viewVec[1] *= -$cameraSign;
!  $viewVec[2] *= -$cameraSign;

!  cameraViewVector($view, @viewVec, @pivotVec, $copies, $cameraRotX);
!}


#### cameraViewVector
!sub cameraViewVector
!{
!  use Math::Quaternion;
!  my ($view, $viewVecX, $viewVecY, $viewVecZ, $pivotVecX, $pivotVecY, $pivotVecZ, $copies, $cameraRotX) = @_;

!  my @viewVec = ( $viewVecX, $viewVecY, $viewVecZ);
!  my @pivotVec = ( $pivotVecX, $pivotVecY, $pivotVecZ);

#  Normalize the view vector
!  my $invMag = 1/sqrt($viewVec[0]*$viewVec[0] + $viewVec[1]*$viewVec[1] + $viewVec[2]*$viewVec[2]);
!  $viewVec[0] *= $invMag;
!  $viewVec[1] *= $invMag;
!  $viewVec[2] *= $invMag;

#  Assume the machine axis is the Z-axis if not defined
!  if ( @rotAxis == 0 )
!  {
!    @rotAxis = ( 0, 0, 1);
!  }

# Rotate pivotVec and viewVec
!  if ( defined($numComponents) && $copies > 1 )
!  {
!    my $angle = 0.5 * ($copies - 1) * Math::Trig::pi2 / $numComponents;
!    my $qrot = Math::Quaternion->new({axis=>[$rotAxis[0],$rotAxis[1],$rotAxis[2]],angle=>$angle});
!    @pivotVec = $qrot->rotate_vector(@pivotVec);
!    @viewVec = $qrot->rotate_vector(@viewVec);
!  }

# Initial viewer camera orientation before rotation
!  my @startVec = (0, 0, -1);

# Generate the quanternion for the view vector
!  my $q1 = Math::Quaternion->unit;
!  if ( $startVec[2]*$viewVec[2] == -1 )
!  {
!    $q1 = Math::Quaternion::rotation(Math::Trig::pi, 1, 0, 0);
!  }
!  elsif ( $startVec[2]*$viewVec[2] == 1 )
!  {
!  }
!  else
!  {
!    $q1 = Math::Quaternion::rotation(\@viewVec, \@startVec);
!  }

# Rotate the machine axis by q1 and check if the view is oriented along the viewer Z-axis
!  my @sZ = $q1->rotate_vector(@rotAxis);
!  if ( abs($sZ[2]) > 0.9 )
!  {
#    If the view is aligned with the Z-axis then set the camera twist angle so that
#    the region centroid is vertically positioned above the origin
!    my @sY = $q1->rotate_vector(@pivotVec);
!    $angle = Math::Trig::pip2() - atan2($sY[1], $sY[0]);
!  }
!  else
!  {
#    If view is not aligned then set the camera twist angle so that machine axis is vertical
!    $angle = -1*Math::Trig::pip2() - atan2($sZ[1], $sZ[0]);
!  }

# Rotate the camera about the screen Z-axis by the specified twist angle
!  $q2 = Math::Quaternion::rotation($angle, 0, 0, 1);

# Rotate the camera about the screen X-axis by the specified angle
!  $q3 = Math::Quaternion::rotation($cameraRotX, 1, 0, 0);

#  Multiply the quaternions and normalize (this is not communitive)
!  my $qFinal = $q3 * $q2 * $q1;
!  $qFinal = $qFinal->normalize;

# Set the camera to the pivot point and computed quaternion
VIEW:$view
  CAMERA:
    Option = Pivot Point and Quaternion
    Pivot Point = $pivotVec[0], $pivotVec[1], $pivotVec[2]
    Rotation Quaternion = $qFinal->[1], $qFinal->[2], $qFinal->[3], $qFinal->[0]
  END
END
!}

