=head1 NAME

  CFX5::Simulation::Configuration::Remeshing::Remesh::ICEMCFD_rpl - RPL file object
=head1 SYNOPSIS

=head1 DESCRIPTION

$Id$

=cut

package CFX5::Simulation::Configuration::Remeshing::Remesh::ICEMCFD_rpl ;
@ISA=qw(CFX5::Output::File);

use strict;

use CFX5::Output::File ; 

use CFX5::Output qw(:all);

#
################################################################################
# Output Routines
################################################################################
#
#-----------------------------------------------------------------------
# Generic Set Command
#-----------------------------------------------------------------------
#
# Example: 
#   $cfxParams_obj->Set_Parameter(
#     ( "ResFile"  => $resfile, 
#       "MeshFile" => "msh", )
#   ) ; 
#
# Produces:
#   set MeshFile msh
#   set ResFile /home/sreuss/mpf_mmSubD_001.dir/res
#
# NOTES:
# * hashes are accepted and processed
#
sub Set_Parameter {
  my $self = shift; 
  my %params = @_; 
  
  my $key; 
  my $value; 
  if (my $fh=$self->open()) {
    while (($key,$value) = each %params) {
      chomp $value;
      
      # Cleanup values for ICEM
      #  --> spaces and backslashes need escaping
      #      FRUSTRATINGLY... there seems to be little consistency here...
      #      I've found that:
      #      - spaces in values should not be escaped
      $key =~ s/\\/\//g ;
      $key =~ s/ /\\ /g ;
      $value =~ s/\\/\//g ;
      #$value =~ s/ /\\ /g ;
      
      print $fh "set $key $value\n";
    }
    $self->close();
  } else {
    _error("Set_Parameter: Could not write to $self->{filename}");
  }
  1;
}
#
#-----------------------------------------------------------------------
# Set entry in array of scalar values
#-----------------------------------------------------------------------
#
# Example: 
#  $cfxParams_obj->Set_ScalarArray("ScalarParam",$name,$value);
#
# Produces:
#   set ScalarParam(CCL Param 1 1) CCL Param 1 1 Monitor Point
#
# NOTES:
# * hashes are accepted and processed, but note that the
#   first argument will be used as the output array name for all
#   hash entries
#
sub Set_ScalarArray {
  my $self = shift; 
  my $arrayName = shift ; 
  my %params = @_; 
  
  my $key; 
  my $value; 
  if (my $fh=$self->open()) {
    while (($key,$value) = each %params) {
      chomp $value;
      
      # Cleanup values for ICEM
      #  --> spaces and backslashes need escaping
      $key =~ s/\\/\//g ;
      $key =~ s/ /\\ /g ;
      $value =~ s/\\/\//g ;
      $value =~ s/ /\\ /g ;
      
      print $fh "set $arrayName($key) $value\n";
    }
    $self->close();
  } else {
    _error("Set_ScalarArray: Could not write to $self->{filename}");
  }

  1;
}
#
#-----------------------------------------------------------------------
# Set entry in array of vector values
#-----------------------------------------------------------------------
#
# Example: 
#   $cfxParams_obj->Set_VectorArray("Displacement",$part,@disp);
#
# Produces:
#   set Displacement(Map 1 2 Part 5) {0.00999999977648258 0 0}
#
# NOTES:
# * hashes are NOT accepted
#
sub Set_VectorArray {
  my $self = shift; 
  my $arrayName = shift; 
  my $key = shift; 
  my @value = @_;
  
  # Cleanup values for ICEM
  #  --> spaces and backslashes need escaping
  $key =~ s/\\/\//g ;
  $key =~ s/ /\\ /g ;
  
  if (my $fh=$self->open()) {
    print $fh "set $arrayName($key) {@value}\n";
    $self->close();
  } else {
    _error("Set_VectorArray: Could not write to $self->{filename}");
  }
  1;
}

1 ;
