;+
; NAME:
;       MC_KUMMER
;
; PURPOSE: 
;       Computes the Kummer or confluent hypergeometric function
;
; CATEGORY:
;       Math.
;
; CALLING SEQUENCE:
;       res =  mc_kummer(a,b,x)
;
; INPUTS:
;       a:    parameter array
;       b:    parameter array
;       x:    variable array
;
; OUTPUTS:
;       res:  confluent hypergeometric series
;
; EXAMPLE:
;       IDL> den = mc_kummer(-0.5d*ka , 0.5d , -0.5d*peclet_l)
;  
; PROCEDURE:
;       mc_kummer calls the external fortran program
;       confluent_hypergeometric_series_M to compute the Kummer function
;
; REFERENCE:
;       Weisstein E.W. (2004b) Hypergeometric function.
;       In: MathWorld - A Wolfram Web Resource, 
;       Website: http://mathworld.wolfram.com/HypergeometricFunction.html
;
; MODIFICATION HISTORY:
;       Written by: JO, Sep 2004
;       Modfied     MC, Feb 2005 - a, b, x arrays
;                   MC, Jun 2007 - undef
;-
FUNCTION MC_KUMMER, a, b, x, undef=undef
  COMPILE_OPT idl2, 
  ON_ERROR, 2
  ; ---
  os = ([1,2,3,4,5])[(where([ 'darwin', 'win32', 'linux', 'osf', 'aix' ] eq strlowcase(!version.os)))[0]]
  ;
  if n_elements(undef) eq 0 then undef = -9999.
  aa = a
  bb = b
  xx = x
  iiundef = where(aa eq undef or bb eq undef or xx eq undef, undefcount)
  if undefcount gt 0 then begin
      aa[iiundef] = 0.5
      bb[iiundef] = 0.5
      cc[iiundef] = 0.5
  endif
  ;
  tempfile = mc_tmp()
  reportfile = mc_tmp()
  ;---
  n = n_elements(x)
  result = ''
  ;---
  get_lun, unit
  openw, unit, tempfile
  printf, unit, n
  for i=0, n-1 do printf, unit, a[i], b[i], x[i]
  free_lun, unit
  ; --- Run C program
  newpath=mc_setup(/mcbin)
  case os of
      1: begin
          ccode = newpath+'confluent_hypergeometric_series_M.Mac'
          if not file_test(ccode) then $
            message,'No executable found for this platform: '+ccode
          spawn, ccode+' < ' + tempfile + ' > ' + reportfile, summary, /sh
      end
      2: begin
          ccode=newpath+'confluent_hypergeometric_series_M.exe'
          if not file_test(ccode) then $
            message,'No executable found for this platform: '+ccode
          spawn, ccode+' < ' + tempfile + ' > ' + reportfile, summary, /log_output
      end
      3: begin
          spawn, 'uname -a', uname, /sh
          uname = strmid(uname,0,6)
          if uname eq 'obelix' then $
            ccode = newpath+'confluent_hypergeometric_series_M.Linux.obelix' $
          else if uname eq 'asterix' then $
            ccode = newpath+'confluent_hypergeometric_series_M.Linux.asterix' $
          else $
            ccode = newpath+'confluent_hypergeometric_series_M.Linux'
          if not file_test(ccode) then $
            message,'No executable found for this platform: '+ccode
          spawn, ccode+' < ' + tempfile + ' > ' + reportfile, summary, /sh
      end
      4: begin
          ccode = newpath+'confluent_hypergeometric_series_M.DEC'
          if not file_test(ccode) then $
            message,'No executable found for this platform: '+ccode
          spawn, ccode+' < ' + tempfile + ' > ' + reportfile, summary, /sh
      end
      5: begin
          ccode = newpath+'confluent_hypergeometric_series_M.IBM'
          if not file_test(ccode) then $
            message,'No executable found for this platform: '+ccode
          spawn, ccode+' < ' + tempfile + ' > ' + reportfile, summary, /sh
      end
  endcase
  ; ---
  res = dblarr(n)
  get_lun, unit
  openr, unit, reportfile
  for i=0, n-1 do begin
      readf, unit, result
      res[i] = double(result)
  endfor
  free_lun, unit
  ; ---
  file_delete, tempfile, reportfile
  ;
  if undefcount gt 0 then res[iiundef] = undef
  ;
  if n gt 1 then return, res else return, res[0]
  ;
END
;-

