=head1 NAME

CFX5::CUEI - configuration variables for CUE components

=head1 DESCRIPTION

This package provides common configuration information for the various
CUE components, and a little common functionality.

  $Id$

=cut

package CFX5::CUEI;

use strict;

use CFX5::PathManip qw(prepend_to_path join_file list_to_path
                       path_to_list path_list_remove_dups get_cwd fullpath);
use CFX5::Config qw(%Config export_conf append_to_libpath prepend_to_libpath
                    append_to_execpath prepend_to_execpath);
use CFX5::CCLI;
use CFX5::Output qw(:all);

=head1 VARIABLES

=cut

sub _ldir {
  if ($Config{CUE_ISLOCAL}) {
    return join_file($Config{CUE_ROOT},shift);
  } else {
    return $Config{CUE_ROOT};
  }
}
# like _ldir but for things which are currently not installed
sub _ldiru {
  return join_file($Config{CUE_ROOT},shift);
}

use CFX5::Config::def
  # these aren't exported, but I use them internally.  The rest of the
  # settings depend on them, so they must be set ASAP!
  CUE_CHECK_FOR_VIEWER => sub { 'no'; },
  CUE_GRAPHICS => sub { 'ogl'; },
  CUE_BINEXT => sub { '.exe'; },
  CUE_ISLOCAL => sub { ''; },

  # this will be _debug in local mode with -debug, or empty otherwise.
  # It's used for directories like bin_debug/linux, which are
  # different centrally.
  CUE_DIRSUFF => sub {
    if ($Config{CUE_ISLOCAL} and $Config{CFX5DEBUG}) {
      return '_debug';
    } else {
      return '';
    }
  },

  # root directory for CUE install stuff
  CUE_ROOT => sub {
    if ($Config{CUE_ISLOCAL}) {
      return get_cwd();
    } else {
      return join_file($Config{CFX5ROOT},'cfxpost',$Config{CFXBUILDID});
    }
  },

  CUE_DIR => sub { $Config{CUE_ROOT}; },
  CUE_DIR_UNIX => sub { (my $d=$Config{CUE_DIR}) =~ s!\\!/!g; $d; },

  # directories for things
  CUE_POSTENGINE_DIR => sub { 
    $Config{CUE_ISLOCAL} ? _ldiru('PostEngine') : $Config{CFX5EXECDIR};
  },
  CUE_POSTGUI_DIR => sub { 
    # in local mode, this is used for both execs and datafiles; in
    # non-local mode, it's only used to pick up datafiles by having
    # /etc tacked on the end. :-(
    $Config{CUE_ISLOCAL} ? _ldiru('PostGui') : $Config{CFX_DATA_DIR};
  },
  CUE_PREENGINE_DIR => sub { 
    $Config{CUE_ISLOCAL} ? _ldiru('PreEngine') : $Config{CFX5EXECDIR};
  },
  CUE_PREGUI_DIR => sub { 
    # in local mode, this is used for both execs and datafiles; in
    # non-local mode, it's only used to pick up datafiles by having
    # /etc tacked on the end. :-(
    $Config{CUE_ISLOCAL} ? _ldiru('PreGui') : $Config{CFX_DATA_DIR};
  },
  CUE_SMENGINE_DIR => sub { 
      $Config{CUE_ISLOCAL} ? _ldiru('SolverManager') : $Config{CFX5EXECDIR}; },
  CUE_SMGUI_DIR => sub { 
      $Config{CUE_ISLOCAL} ? _ldiru('SolverManager') : $Config{CFX_DATA_DIR}; },

  CUE_TGENGINE_DIR => sub { 
    $Config{CUE_ISLOCAL} ? _ldiru('TGEngine') : $Config{CFX5EXECDIR};
  },
  CUE_TGGUI_DIR => sub { 
    # in local mode, this is used for both execs and datafiles; in
    # non-local mode, it's only used to pick up datafiles by having
    # /etc tacked on the end. :-(
    $Config{CUE_ISLOCAL} ? _ldiru('TGGui') : $Config{CFX5ROOT};
  },
  CUE_MONDATA_DIR => sub {
    # in local mode, this is used for both execs and datafiles; in
    # non-local mode, it's only used to pick up datafiles by having
    # /etc tacked on the end. :-(
    $Config{CUE_ISLOCAL} ? _ldiru('MonitorDataExporter') : $Config{CFX5ROOT};
  },


  CUE_CHARTER_DIR => sub { 
    if ($Config{CUE_ISLOCAL}) {
      return join_file(_ldir('Charter'),'bin'.$Config{CUE_DIRSUFF},$Config{CUEOS});
    } else {
      return $Config{CFX5EXECDIR};
    }
  },
  CUE_CHARTVIEWER_DIR => sub { 
    if ($Config{CUE_ISLOCAL}) {
      return join_file(_ldir('ChartViewer'),'bin'.$Config{CUE_DIRSUFF},$Config{CUEOS});
    } else {
      return $Config{CFX5EXECDIR};
    }
  },
  CUE_IMAGECONVERT_DIR => sub { 
    if ($Config{CUE_ISLOCAL}) {
      return join_file(_ldir('ImageConvert'),'bin'.$Config{CUE_DIRSUFF},$Config{CUEOS});
    } else {
      return $Config{CFX5EXECDIR};
    }
  },

  # this is used for the non-local installations so we have a single
  # place we can change
  CUE_EXEC_ROOT => sub { $Config{CFX5EXECDIR}; },

  # "The CUE_EXE_DIR environment variable is set for the charting
  # routines which spawn new applications, and require a path
  # to the location of the executables."
  CUE_EXE_DIR => sub { $Config{CUE_POSTENGINE_DIR}; },

  # directory for shared libraries and perl libraries
  CUE_LIB_DIR => sub { $Config{CUE_ISLOCAL} ? join_file($Config{CUE_ROOT}, "lib", $Config{CFX5OS} . $Config{CUE_DIRSUFF}) : $Config{CFX5LIBDIR}; },


  CUE_POSTGUI_EXE => sub { 
    if ($Config{CUE_ISLOCAL}) {
      return join_file($Config{CUE_POSTGUI_DIR},"bin$Config{CUE_DIRSUFF}",$Config{CUEOS},'PostGui_ogl'.$Config{CUE_BINEXT});
    } else {
      return join_file($Config{CUE_EXEC_ROOT},'PostGui_ogl'.$Config{CUE_BINEXT}); 
    }
  },
  CUE_POSTENGINE_EXE => sub { 
    if ($Config{CUE_ISLOCAL}) {
      return join_file($Config{CUE_POSTENGINE_DIR},"bin$Config{CUE_DIRSUFF}",$Config{CUEOS},'PostEngine'.$Config{CUE_BINEXT});
    } else {
      return join_file($Config{CUE_EXEC_ROOT},'PostEngine'.$Config{CUE_BINEXT});
    }
  },
  CUE_PREGUI_EXE => sub { 
    if ($Config{CUE_ISLOCAL}) {
      return join_file($Config{CUE_PREGUI_DIR},"bin$Config{CUE_DIRSUFF}",$Config{CUEOS},'PreGui_ogl'.$Config{CUE_BINEXT});
    } else {
      return join_file($Config{CUE_EXEC_ROOT},'PreGui_ogl'.$Config{CUE_BINEXT}); 
    }
  },
  CUE_PREENGINE_EXE => sub { 
    if ($Config{CUE_ISLOCAL}) {
      return join_file($Config{CUE_PREENGINE_DIR},"bin$Config{CUE_DIRSUFF}",$Config{CUEOS},'PreEngine'.$Config{CUE_BINEXT});
    } else {
      return join_file($Config{CUE_EXEC_ROOT},'PreEngine'.$Config{CUE_BINEXT});
    }
  },
  CFX5_CUESM_EXEC => sub {
    if ($Config{CUE_ISLOCAL}) {
      return join_file($Config{CUE_SMGUI_DIR},"bin$Config{CUE_DIRSUFF}",$Config{CUEOS},'SolverManager'.$Config{CUE_BINEXT});
    } else {
        return join_file($Config{CUE_EXEC_ROOT},'SolverManager'.$Config{CUE_BINEXT}); }
  },
  CUE_TGGUI_EXE => sub { 
    if ($Config{CUE_ISLOCAL}) {
      return join_file($Config{CUE_TGGUI_DIR},"bin$Config{CUE_DIRSUFF}",$Config{CUEOS},'TGGui_ogl'.$Config{CUE_BINEXT});
    } else {
      return join_file($Config{CUE_EXEC_ROOT},'TGGui_ogl'.$Config{CUE_BINEXT}); 
    }
  },
  CUE_TGENGINE_EXE => sub { 
    if ($Config{CUE_ISLOCAL}) {
      return join_file($Config{CUE_TGENGINE_DIR},"bin$Config{CUE_DIRSUFF}",$Config{CUEOS},'TGEngine'.$Config{CUE_BINEXT});
    } else {
      return join_file($Config{CUE_EXEC_ROOT},'TGEngine'.$Config{CUE_BINEXT});
    }
  },
  CUE_MONDATA_EXE => sub {
    if ($Config{CUE_ISLOCAL}) {
      return join_file($Config{CUE_MONDATA_DIR},"bin$Config{CUE_DIRSUFF}",$Config{CUEOS},'MonitorDataExporter'.$Config{CUE_BINEXT});
    } else {
      return join_file($Config{CUE_EXEC_ROOT},'MonitorDataExporter'.$Config{CUE_BINEXT});
    }
  },

  CUE_CALCLIB_DIR => sub { 
    if ($Config{CUE_ISLOCAL}) {
      #return join_file(_ldir('CalcFunctions'),"lib$Config{CUE_DIRSUFF}",$Config{CUEOS});
      # calclibs are now copied into the local lib directory from the build
      return join_file($Config{CUE_ROOT},"lib",$Config{CFX5OS}.$Config{CUE_DIRSUFF});
    } else {
      return $Config{CFX5LIBDIR};
    }
  },

  # perl extension modules
  CUE_PERL_PRELIBSDIR => sub { 
    if ($Config{CUE_ISLOCAL}) {
      my @list;
      push @list, join_file($Config{CUE_PREENGINE_DIR},'perlExt',"lib$Config{CUE_DIRSUFF}",$Config{CUEOS});
      push @list, join_file($Config{CUE_ROOT},'PrePhysics','perlExt',"lib$Config{CUE_DIRSUFF}",$Config{CUEOS});
      push @list, join_file($Config{CUE_ROOT},'GTMAPI','perlExt',"lib$Config{CUE_DIRSUFF}",$Config{CUEOS});
      push @list, join_file($Config{CUE_ROOT},'Units','perlExt',"lib$Config{CUE_DIRSUFF}",$Config{CUEOS});
      push @list, join_file($Config{CUE_ROOT},'CCLCore','perlExt',"lib$Config{CUE_DIRSUFF}",$Config{CUEOS});
      push @list, join_file($Config{CUE_ROOT},'System','perlExt',"lib$Config{CUE_DIRSUFF}",$Config{CUEOS});
      return list_to_path(@list);
    } else {
      return $Config{CUE_LIB_DIR};
    }
  },
  CUE_PERL_POSTLIBSDIR => sub { 
    if ($Config{CUE_ISLOCAL}) {
      return list_to_path(join_file($Config{CUE_POSTENGINE_DIR},'perlExt',"lib$Config{CUE_DIRSUFF}",$Config{CUEOS}),
                          join_file($Config{CUE_ROOT},'System','perlExt',"lib$Config{CUE_DIRSUFF}",$Config{CUEOS}),				
                          join_file($Config{CUE_ROOT},'CCLCore','perlExt',"lib$Config{CUE_DIRSUFF}",$Config{CUEOS}));
    } else {
      return $Config{CUE_LIB_DIR};
    }
  },
  CUE_PERL_TGLIBSDIR => sub { 
    if ($Config{CUE_ISLOCAL}) {
      my @list;
      push @list, join_file($Config{CUE_TGENGINE_DIR},'perlExt',"lib$Config{CUE_DIRSUFF}",$Config{CUEOS});
      push @list, join_file($Config{CUE_ROOT},'System','perlExt',"lib$Config{CUE_DIRSUFF}",$Config{CUEOS});
      push @list, join_file($Config{CUE_ROOT},'CCLCore','perlExt',"lib$Config{CUE_DIRSUFF}",$Config{CUEOS});
      return list_to_path(@list);
    } else {
      return $Config{CUE_LIB_DIR};
    }
  },

  # CCL settings
  CFX_POST_LIBSDIR => sub { $Config{CUE_LOCAL_DATA_DIR}; },
  CFX_POST_LIBS => sub { 'CFXPostRules.ccl;'.join_file($Config{CFX_DATA_DIR},'VARIABLES'); },
  CFX_TG_LIBSDIR => sub { $Config{CUE_LOCAL_DATA_DIR}; },
  CFX_TG_LIBS => sub { 'TGRules.ccl;VARIABLES'; },

  # Default directories for CFX-Pre.  SEAN PEARSON: I have moved the statements to set 
  # CFX_PRE_PHYSLIBSDIR and CFX_PRE_GUILIBSDIR further up
  # because the value of CFX_PRE_PHYSLIBSDIR is used to set RULES and RULES.EXTRA
  CFX_PRE_PHYSLIBSDIR => sub { $Config{CUE_ISLOCAL} 
                                 ? join_file( $Config{CUE_ROOT}, 'PrePhysics', 'etc' )
                                   : $Config{CUE_LOCAL_DATA_DIR}; },
  CFX_PRE_GUILIBSDIR => sub { $Config{CUE_ISLOCAL} 
                                 ? join_file( $Config{CUE_ROOT}, 'PreGui', 'etc' )
                                   : $Config{CUE_LOCAL_DATA_DIR}; },

  # original input files for CFX-Pre.  These are used by CFXPre and
  # CFX5::PreRulesProcessor, if that is called, and are used to
  # generate the input files used at runtime.
  # SEAN PEARSON changed CFX_PRE_RULES_ORIG & CFX_PRE_RULES_EXTRA to be located under
  # CFX_PRE_PHYSLIBSDIR instead of CUE_LOCAL_DATA_DIR
  
  # CFX_PRE_RULES_ORIG => sub { join_file($Config{CUE_LOCAL_DATA_DIR}, 'RULES'); },
  CFX_PRE_RULES_ORIG => sub { join_file($Config{CFX_PRE_PHYSLIBSDIR}, 'RULES'); },
  CFX_PRE_RULES_APPLICATION => sub { join_file($Config{CUE_LOCAL_DATA_DIR}, 'rules.application'); },
  # CFX_PRE_RULES_EXTRA => sub { join_file($Config{CUE_LOCAL_DATA_DIR}, 'RULES.EXTRA'); },
  CFX_PRE_RULES_EXTRA => sub { join_file($Config{CFX_PRE_PHYSLIBSDIR}, 'RULES.EXTRA'); },
  CFX_PRE_EXEC_RULES_ORIG => sub { join_file($Config{CFX_PRE_PHYSLIBSDIR}, 'execrules.ccl'); },

  # default rules files for Pre.  SEAN PEARSON: We don't want a default value for CFX_PRE_RULES_CCL
  # because Pre will use the custom location if the variable has not been set.  We now use variable
  # CFX_PRE_RULES_CCL_DEFAULT in order to initialise CFX_PRE_LIBS.
  # CFX_PRE_RULES_CCL => sub { join_file($Config{CUE_LOCAL_DATA_DIR}, 'CFXPreRules.ccl'); },
  CFX_PRE_RULES_CCL_DEFAULT => sub { join_file($Config{CUE_LOCAL_DATA_DIR}, 'CFXPreRules.ccl'); },
  CFX_PRE_LIBSDIR => sub { $Config{CUE_LOCAL_DATA_DIR}; },
  # CFX_PRE_LIBS => sub { fullpath($Config{CFX_PRE_RULES_CCL}).';'.join_file($Config{CFX_DATA_DIR},'VARIABLES').';'.join_file($Config{CFX_DATA_DIR},'execrules.ccl'); },
  CFX_PRE_LIBS => sub { fullpath($Config{CFX_PRE_RULES_CCL_DEFAULT}).';'.join_file($Config{CFX_DATA_DIR},'VARIABLES').';'.join_file($Config{CFX_DATA_DIR},'execrules.ccl'); },

  # other stuff for Pre : SEAN PEARSON: We don't want a default values for the following three variables
  # because Pre will use the custom location if the variables have not been set. 
  # However we do still want DEFAULT versions to fall back on if the user hasn't set up custom or manually set any variables 
  # CFX_PRE_RULES_CHANGE => sub { join_file($Config{CFX_PRE_LIBSDIR}, 'RULES_CHANGE'); },
  # CFX_PRE_PHYSICS_LIB => sub { join_file($Config{CFX_PRE_PHYSLIBSDIR}, 'CFXPrePhysics.ccl'); },
  # CFX_PRE_GUI_LIB => sub { join_file($Config{CFX_PRE_GUILIBSDIR}, 'CFXPreGui.ccl'); },
  CFX_PRE_RULES_CHANGE_DEFAULT => sub { join_file($Config{CFX_PRE_LIBSDIR}, 'RULES_CHANGE'); },
  CFX_PRE_PHYSICS_LIB_DEFAULT => sub { join_file($Config{CFX_PRE_PHYSLIBSDIR}, 'CFXPrePhysics.ccl'); },
  CFX_PRE_GUI_LIB_DEFAULT => sub { join_file($Config{CFX_PRE_GUILIBSDIR}, 'CFXPreGui.ccl'); },
  CFX_PRE_INIT_DEFAULT => sub { join_file($Config{CUE_LOCAL_DATA_DIR}, $Config{CUE_INIT_FILE}); },

  # the viewer
  # (this is only used in non-GUI mode).  The VIEWER_EXE is the name of
  # the executable *without* the path!
  CUE_VIEWER_DIR => sub { $Config{CFX5EXECDIR}; },
  CUE_VIEWER_EXE => sub { 'viewer_ogl.exe'; },

  # on AIX and DEC, turn off decimation in the viewer by default, as it
  # crashes on many machines.
  VIEWER_DECIMATE => sub { 
    my %disable=(aix => 1, osf => 1);
    return ($disable{$Config{CFX5OS}} ? '-1' : undef);
  },

  # the help browser.  TODO: is this needed?
  CUE_BROWSER_ROOT => sub {
    return join_file($Config{CFX_TOOLS_ROOT},'tascflow_browser');
  },
  CUE_BROWSER_DIR => sub { join_file($Config{CUE_BROWSER_ROOT},'bin',$Config{CFX_OS}); },
  CUE_BROWSER_EXE => sub { join_file($Config{CUE_BROWSER_DIR},'browser'); },

  # misc datafiles
  CUE_LOCAL_DATA_DIR => sub { 
    if ($Config{CUE_ISLOCAL}) {
      return join_file($Config{CUE_POSTENGINE_DIR},'etc','');
    } else {
      return $Config{CFX_DATA_DIR};
    }
  },
  CUE_GLOBAL_DATA_DIR => sub { 
    if ($Config{CUE_ISLOCAL}) {
      return join_file(_ldir('Global'), 'etc');
    } else {
      return $Config{CFX_DATA_DIR};
    }
  },
  CUE_TOP_DATA_DIR => sub {
    if ( $Config{CUE_ISLOCAL} ) {
      return join_file($Config{CUE_ROOT}, 'etc');
    }
    else {
      return $Config{CFX_DATA_DIR};
    }
  },
  CUE_PIXMAP_DIR => sub { 
    return join_file($Config{CUE_GLOBAL_DATA_DIR},'icons');
  },
  CFX_CUE_ICONDIR => sub { 
    if ($Config{CUE_ISLOCAL}) {
      return join_file($Config{CUE_POSTGUI_DIR},'etc');
    } else {
      return join_file($Config{CFX_DATA_DIR},'pre');
    }
  },
  CUE_DICT => sub { join_file($Config{CUE_GLOBAL_DATA_DIR},'cue_en.dic'); },
  PLPLOT_LIB => sub { $Config{CUE_GLOBAL_DATA_DIR}; },

  TASC_FONT_DIR => sub { $Config{CUE_GLOBAL_DATA_DIR}; },
  TASC_FONTS => sub { 'serif sanserif'; },

  # sigh ...
  CFX5_DIR => sub { $Config{CFX5ROOT}; },
  CUEOS => sub { return $Config{CFX5OS}; },
 
  # STLPORT variable
  #STLPORTDIR => sub { join_file($Config{CFX_TOOLS_ROOT}, 'STLport-4.6.2'); },
  #STLPORTLIBDIR => sub { join_file($Config{STLPORTDIR}, 'lib'); },

  # SM-specific variables
  CUESM_ETC_DIR => sub { 
    if ($Config{CUE_ISLOCAL}) {
       join_file($Config{CUE_ROOT},'etc');
    } else {
       $Config{CFX_DATA_DIR}; 
    }
  },
  CUESM_RESOURCE_DIR => sub { 
    if ($Config{CUE_ISLOCAL}) {
       join_file($Config{CUE_SMGUI_DIR},'etc');
    } else {
       $Config{CFX_DATA_DIR}; 
    }
  },
  CFX5_CUESM_CCL_LIBS => sub { join(';', join_file($Config{CUESM_ETC_DIR},'smrules.ccl'), join_file($Config{CFX_DATA_DIR},'execrules.ccl')); },

  # TG-specific variables
  CUE_TG_STRAIGHT_PASSAGE => sub { 1; },
  ICEM_AI_ENVIRONMENT => sub { 1; },
  AI_ENV_OPT_INITLICENSE => sub { 0; },
  AWP_ROOT => sub { join_file($Config{ANSYS_COMMON_ROOT},'..'); },

  # ICEM base variables
  ICEMCFD_DIR    =>  sub { join_file($Config{CFX_TOOLS_ROOT}, 'icemcfd-'.$Config{CFXBUILDID_MAJOR_MINOR}); },
  ICEMCFD_BINDIR =>  sub { join_file($Config{ICEMCFD_DIR}, $Config{ANSYSOS}, 'IcemExe2Cfx'); },
  ICEMCFD_LIBDIR =>  sub { join_file($Config{ICEMCFD_DIR}, 'lib' ); },

  # TG ICEM variables
  MED_ROOT => sub { $Config{ICEMCFD_DIR}; }, 
  ICEM_ACN => sub { $Config{MED_ROOT}; },
  MED_LIB  => sub { join_file($Config{ICEMCFD_LIBDIR}, 'med'); },
  ICEMCFD_TKLIBS => sub { join_file($Config{MED_ROOT}, 'lib'); },

  # Post ICEM variables
  CFX_POST_ICEMCFD_DIR    => sub { join_file($Config{ICEMCFD_DIR}, $Config{ANSYSOS}); },
  CFX_POST_ICEMCFD_BINDIR => sub { $Config{ICEMCFD_BINDIR}; },
  CFX_POST_ICEMCFD_LIBDIR => sub { join_file($Config{ICEMCFD_LIBDIR}, 'resultlib' ); },

  # Fluentio variables
  CFX_FLUENTIO_LIBDIR => sub { join_file($Config{CFX_ROOT}, 'support', 'fluentio', 'lib', $Config{ANSYSOS}); },
  
  # Intel MKL variables
  CFX_INTEL_LIBDIR => sub { join_file($Config{CFX5LIBDIR}, 'ifort'); },

  TASCUTS_OS => sub {
    my $rv=$Config{CFX_OS};
    if ($Config{CFX5OS} =~ m!-ia64!) {
      $rv .= '-IA64';
    }
    # Don't want to match winnt-amd64!
    if ($Config{CFX5OS} eq "linux-amd64") {
      $rv .= '-AMD64';
    }
    $rv;
  },
  TASCUTS_DIR => sub { join_file($Config{CFX_TOOLS_ROOT}, 'tascuts-2.12'); },
  TASCUTS_BINDIR => sub { join_file($Config{TASCUTS_DIR}, 'bin', $Config{TASCUTS_OS}); },
  TASCUTS_UTILITY =>sub { join_file($Config{TASCUTS_DIR}, 'Utility'); },

  ;

=head1 FUNCTIONS

=head2 check_graphics

=cut

sub check_graphics {
  my $graphics=shift;
  my %ok;
  if ($Config{CFX5OS} eq "linux" or $Config{CFX5OS} eq "linux-amd64") {
    %ok=(ogl => 1, mesa => 1);
  } else {
    %ok=(ogl => 1);
  }
  if ($ok{$graphics}) {
    return 1;
  } else {
    _error("Invalid graphics mode $graphics, must be", keys %ok);
    return '';
  }
}

=head2 export_cue_locale

=cut

sub export_cue_locale {
  if ($Config{CFX5OS} eq "linux-amd64" and !$Config{CUE_OVERRIDE_LOCALE}) {
    $Config{LC_NUMERIC} = "C";
    export_conf(qw(LC_NUMERIC));
  }
}

=head2 export_common_conf

=cut

sub export_common_conf {
  CFX5::CCLI::export_parser_conf();

  # we don't specify this as a default in the normal way, as it's not!
  # This variable is deliberately set to different values by different
  # packages.  Currently all the CUE components use this same setting.
  $Config{CFX5_CCL_PARSER_PACKAGE}='CUEPost';

  export_conf
    (qw(CUE_INIT_FILE
        CUE_DIR
        CUE_POSTENGINE_EXE CUE_POSTGUI_EXE
        CUE_PREENGINE_EXE CUE_PREGUI_EXE
        CUE_POSTGUI_DIR CUE_PREGUI_DIR
        CFX5_CUESM_EXEC
        CUE_CHARTER_DIR
        CUE_CHARTVIEWER_DIR
        CUE_IMAGECONVERT_DIR
        CUE_EXE_DIR
        CUE_BROWSER_DIR CUE_BROWSER_EXE
        CUE_DICT
        TASC_FONT_DIR TASC_FONTS
        PERL5LIB
        PERL5SHELL
        CFX_DATA_DIR CFX5BINDIR CFX5EXECDIR
        CUE_LOCAL_DATA_DIR CUE_GLOBAL_DATA_DIR CUE_PIXMAP_DIR CUE_TOP_DATA_DIR
        CUE_PRE_CCL_LIBS CUE_PRE_CCL_LIBSDIR
        CUE_VIEWER_DIR CUE_VIEWER_EXE
        VIEWER_DECIMATE
        CFX_EG_DIR
        CFX5_CCL_PARSER_PACKAGE
        CFX5EDITOR CFX5VIEWER CFX5XTERM
        CFX_USER_CONFIG_DIR
        CLASSPATH
        CFX_HELP_DIR
        CFX_HELP_JARDIR
        CFX_LANGUAGE
        CFX_QT_DIR
        QT_PLUGIN_PATH
        AWP_COMMON_FILES_ROOT
       ));

  # ensure we have all the QT etc parts we need
  prepend_to_libpath($Config{CUE_LIB_DIR},
                     $Config{CFXCPP_LIBDIR},
                     $Config{CFX_QT_LIBDIR},
                     $Config{CFX_QWT_LIBDIR},
                     $Config{CFX_STL_LIBDIR},
                     $Config{CFX_STLPORT_LIBDIR},
                     $Config{CFX_XERCES_LIBDIR},
                     $Config{CFX_BOOST_LIBDIR},
                     $Config{APIP_INSTALL_ROOT});

  if ( $Config{CUE_GRAPHICS} eq "mesa" ) {
    prepend_to_libpath($Config{CFX_MESA_LIBDIR});
  }

  # these are vital to the future of humanity
  if ($Config{CUE_ISLOCAL}) {
    prepend_to_libpath($Config{CUE_CALCLIB_DIR});
  }

  export_cue_locale();

  check_common_conf();
  check_graphics($Config{CUE_GRAPHICS});
}

=head2 export_post_conf

=cut

sub export_post_conf {

  $Config{CUE_CHECK_FOR_VIEWER} = 'yes';

  # this needs to be set up with forward slashes rather than
  # backslashes so the CUEPostInit.ccl can be loaded ...
  ($Config{CFX5_CCL_LIBSDIR} = $Config{CFX_POST_LIBSDIR}) =~ s!\\!/!g;
  $Config{CFX5_CCL_LIBS} = $Config{CFX_POST_LIBS};

  prepend_to_path(\$Config{PERL5LIB}, $Config{CUE_PERL_POSTLIBSDIR});

  # TODO: this should probably be done for all platforms
  if ($Config{CFX5OS} eq 'hpux') {
    append_to_libpath(join_file($Config{CFX_TOOLS_ROOT}, $Config{CFX_OS}, 'lib'));
  }

  $Config{CUE_INIT_FILE} = 'CFXPostInit.ccl';

  export_common_conf();

  # Add the icem bin dir
  prepend_to_libpath($Config{CFX_POST_ICEMCFD_LIBDIR});
  prepend_to_libpath($Config{CFX_FLUENTIO_LIBDIR});
  prepend_to_libpath(join_file($Config{CFX_POST_ICEMCFD_BINDIR}, 'syslib'));

  # Workaround TASCFlow I/O issue on linux
  if($Config{CFX5OS} eq "linux" or $Config{CFX5OS} eq "linux-amd64"){
    $Config{GFORTRAN_CONVERT_UNIT} = 'SWAP';
    export_conf(qw(GFORTRAN_CONVERT_UNIT));
  }
  export_conf(qw(PLPLOT_LIB CFX_POST_ICEMCFD_DIR CFX_POST_ICEMCFD_BINDIR));
  
  # Add Intel libraries to the lib path.
  if($Config{CFX5OS} eq "linux-amd64"){
    prepend_to_libpath($Config{CFX_INTEL_LIBDIR});
  }
}

=head2 export_sm_conf

=cut

sub export_sm_conf {

  # ensure we have all the QT etc libraries we need exported to the standard
  # library path so they can be piacked up at run time
  prepend_to_libpath($Config{CUE_LIB_DIR},
                     $Config{CFX_QT_LIBDIR},
                     $Config{CFX_QWT_LIBDIR},
                     $Config{CFX_QWTPOLAR_LIBDIR},
                     $Config{CFX_STL_LIBDIR},
                     $Config{CFX_STLPORT_LIBDIR},
                     $Config{CFX_BOOST_LIBDIR});

  export_common_conf();

  # which need to be exported along with a number of other variables common
  # with at least one other application and any others defined for SolverManager
  # alone.
  export_conf(qw(CFX5ROOT
                 CFX_CMD_DIR CFX_ICON_DIR CFX_CONFIG_DIR
                 CFX5_HOSTS_CCL CFX5_START_METHODS_CCL CFX_HOST CFX_FULLHOST
                 CUESM_SCRIPT_PATH
                 CUESM_BROWSER_DIR CUESM_HELP_DIR
                 CUESM_ETC_DIR CUESM_RESOURCE_DIR CFX5_CUESM_CCL_LIBS
                 CFX_FLUENTIO_LIBDIR));
}

=head2 export_pre_conf

=cut

sub export_pre_conf {
  # for Pre, we don't have a central "CFX-Pre" directory ATM, so we
  # use the central builds and pretend they're local
  #unless ($Config{CUE_ISLOCAL}) {
  #  $Config{CUE_ROOT}=join_file($Config{CFX5ROOT},'cue',$Config{CFXBUILDID});
  #  # I can't see why this is necessary, but ...
  #  $Config{CUE_DIR}=$Config{CUE_PREENGINE_DIR};
  #  $Config{CUE_ISLOCAL}=1;
  #}

  $Config{CUE_CHECK_FOR_VIEWER} = 'yes';

  $Config{CUE_POSTENGINE_DIR} = $Config{CUE_PREENGINE_DIR};
  #$Config{CUE_POSTGUI_DIR} = $Config{CUE_PREGUI_DIR};
  $Config{CUE_POSTENGINE_EXE} = $Config{CUE_PREENGINE_EXE};
  #$Config{CUE_POSTGUI_EXE} = $Config{CUE_PREGUI_EXE};

  #($Config{CFX5_CCL_LIBSDIR} = $Config{CFX_DATA_DIR}) =~ s!\\!/!g;
  #$Config{CFX5_CCL_LIBSDIR} = $Config{CFX_PRE_LIBSDIR};
  #$Config{CFX5_CCL_LIBS} = $Config{CFX_PRE_LIBS};
  $Config{CUE_PRE_CCL_LIBSDIR} = $Config{CFX_PRE_LIBSDIR};
  $Config{CUE_PRE_CCL_LIBS} = $Config{CFX_PRE_LIBS};

  prepend_to_path(\$Config{PERL5LIB}, $Config{CUE_PERL_PRELIBSDIR});

  $Config{CUE_INIT_FILE} = 'CFXPreInit.ccl';

  $Config{CUE_DIR} = $Config{CFX_DATA_DIR};

  #$Config{CUE_PREGUI_DIR}=$Config{CFX_CUE_DATADIR};

  export_common_conf();

#  SEAN PEARSON: ADDING RULES, RULES.EXTRA & rules.application, and DEFAULT paths to the exported config
#  export_conf(qw(CFX5_MATERIALS_DIR CFX5_REACTIONS_DIR  CFX_PRE_RULES_CHANGE
#                 CFX_PRE_PHYSICS_LIB CFX_PRE_GUI_LIB CFX_PRE_LIBSDIR CFX5_LICENSED_OPTIONS));
  export_conf(qw(CFX5_MATERIALS_DIR CFX5_REACTIONS_DIR  CFX_PRE_RULES_CHANGE
                 CFX_PRE_PHYSICS_LIB CFX_PRE_GUI_LIB CFX_PRE_LIBSDIR CFX5_LICENSED_OPTIONS
                 CFX_PRE_RULES_ORIG CFX_PRE_RULES_APPLICATION CFX_PRE_RULES_EXTRA
                 CFX_PRE_RULES_CCL_DEFAULT CFX_PRE_RULES_CHANGE_DEFAULT CFX_PRE_PHYSICS_LIB_DEFAULT
                 CFX_PRE_GUI_LIB_DEFAULT CFX_PRE_INIT_DEFAULT CFX_CUSTOM_DATA_DIR CFX_NO_CUSTOM_DATA
                 CFX_PRE_DISABLE_PROGRESS));



}

=head2 export_tg_conf

=cut

sub export_tg_conf {
  # for TG, we don't have a central "CFX-TG" directory ATM, so we
  # use the central builds and tgtend they're local
  #unless ($Config{CUE_ISLOCAL}) {
  #  $Config{CUE_ROOT}=join_file($Config{CFX5ROOT},'cue',$Config{CFXBUILDID});
  #  # I can't see why this is necessary, but ...
  #  $Config{CUE_DIR}=$Config{CUE_TGENGINE_DIR};
  #  $Config{CUE_ISLOCAL}=1;
  #}

  $Config{CUE_CHECK_FOR_VIEWER} = 'yes';

  $Config{CUE_POSTENGINE_DIR} = $Config{CUE_TGENGINE_DIR};
  $Config{CUE_POSTGUI_DIR} = $Config{CUE_TGGUI_DIR};
  $Config{CUE_POSTENGINE_EXE} = $Config{CUE_TGENGINE_EXE};
  #$Config{CUE_POSTGUI_EXE} = $Config{CUE_TGGUI_EXE};
  prepend_to_libpath($Config{CFX_FLUENTIO_LIBDIR});

  ($Config{CFX5_CCL_LIBSDIR} = $Config{CFX_TG_LIBSDIR}) =~ s!\\!/!g;
  #$Config{CFX5_CCL_LIBSDIR} = $Config{CFX_TG_LIBSDIR};
  $Config{CFX5_CCL_LIBS} = $Config{CFX_TG_LIBS};

  prepend_to_path(\$Config{PERL5LIB}, $Config{CUE_PERL_TGLIBSDIR});

  $Config{CUE_INIT_FILE} = 'CUETGInit.ccl';

  #$Config{CUE_DIR} = $Config{CFX_DATA_DIR};
  $Config{CUE_DIR} = $Config{CFX5ROOT};

  #$Config{CUE_TGGUI_DIR}=$Config{CFX_CUE_DATADIR};

  export_common_conf();

  prepend_to_libpath($Config{CUE_LIB_DIR}, $Config{CFX5LIBDIR}, $Config{CFX_STLPORT_LIBDIR}, $Config{MED_LIB});
  prepend_to_execpath($Config{TASCUTS_BINDIR});

  ## This is needed to pick up the TK and TCL libs at runtime.
  prepend_to_execpath($Config{ICEMCFD_TKLIBS});

  $Config{CFX5_DIR} = $Config{CFX_TOOLS_ROOT};

  # override any preexisting TASC_UTILITY with the TG-supplied version
  $Config{TASC_UTILITY} = $Config{TASCUTS_UTILITY};

  export_conf(qw(CUE_TG_STRAIGHT_PASSAGE
                 ICEM_AI_ENVIRONMENT
                 AI_ENV_OPT_INITLICENSE
                 AWP_ROOT

                 CUE_TGGUI_DIR
                 CUE_POSTGUI_DIR
                 CUE_DIR CUE_DIR_UNIX
                 CFX5_DIR

                 MED_ROOT
                 ICEM_ACN

                 TASCUTS_DIR
                 TASCUTS_BINDIR
                 TASCUTS_UTILITY
                 TASC_UTILITY

                ));
}

=head2 check_common_conf

=cut

sub check_common_conf {
  if ( $Config{CUE_CHECK_FOR_VIEWER} eq 'yes' ) {
      check_viewer_conf();
  }
}

=head2 check_viewer_conf

=cut

sub check_viewer_conf {
  my $viewer=join_file($Config{CUE_VIEWER_DIR}, $Config{CUE_VIEWER_EXE});
  CFX5::FileTests::execfile
      ($viewer, "CUE Viewer executable $viewer");
}

1;
