// Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
// Copyright (C) 2009-2011  - DIGITEO - Allan CORNET
//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution.  The terms
// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2.1-en.txt

function startModule()
  if %fftw then
    if getos() == "Windows" then
      librarynamefftw = SCI+"/bin/fftw/libfftw3-3"+getdynlibext();
      librarynamefftw3 = "";
    else
      librarynamefftw = "libfftw3"+getdynlibext();
      // Some distribs/os are not adding the .3 extension...
      librarynamefftw3 = librarynamefftw+".3";
    end

    if ( loadfftwlibrary(librarynamefftw3) | loadfftwlibrary(librarynamefftw)) then
      // replace scilab fft function by fftw
      clearfun('fft');
      newfun('fft', funptr('fftw'));

    else  // if ( loadfftwlibrary(librarynamefftw) )
      settings_file = pathconvert(SCIHOME+"/.scilab_settings", %f, %t)
      w = fileinfo(settings_file);
      show = %t;
      if w <> [] then
        show = grep(mgetl(SCIHOME+"/.scilab_settings"),"displayWarningFFTW=no")==[]
      end
      if show then
        MSG_FTTW = [_("You choose to install scilab with fftw module.");
                  _("This module requires : "+librarynamefftw+" (GPL licence).");
                  _("Scilab will use standard fft by default until you install this library.");
                  _("See help fftw for more information.")];

        if getscilabmode() == "STD" then
          messagebox(MSG_FTTW,"","info");
        else
          warning(MSG_FTTW);
        end
        mputl("displayWarningFFTW=no",SCIHOME+"/.scilab_settings")
      end
    end // if ( loadfftwlibrary(librarynamefftw) )
  end

endfunction

startModule();
clear startModule;