File: idmin.f

package info (click to toggle)
scilab 4.0-12
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 100,640 kB
  • ctags: 57,333
  • sloc: ansic: 377,889; fortran: 242,862; xml: 179,819; tcl: 42,062; sh: 10,593; ml: 9,441; makefile: 4,377; cpp: 1,354; java: 621; csh: 260; yacc: 247; perl: 130; lex: 126; asm: 72; lisp: 30
file content (43 lines) | stat: -rw-r--r-- 1,119 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
      integer function idmin(n, x, incx)
*
*     PURPOSE
*        finds the index of the first element having minimum value
*        without taking into account the nan(s)
*
*     NOTE
*        - original version modified by Bruno (for the nan problem...)
*          (01/01/2003)
*        - this function return 1 if x has only nan components : may be
*          this is not a good behavior
*        - this function doesn't test if n<1 or incx<1 : this is done
*          by the scilab interface
*
      implicit none
      integer n, incx
      double precision x(incx,*)

      double precision xmin
      integer i, j
      external isanan
      integer  isanan

      idmin = 1

*     initialize the min with the first component being not a nan
      j = 1      
      do while ( isanan(x(1,j)) .eq. 1 )
         j = j + 1
         if ( j .gt. n ) return
      enddo
      xmin = x(1,j)
      idmin = j

*     the usual loop
      do i = j+1, n
         if ( x(1,i) .lt. xmin) then  ! a test with a nan must always return false
            xmin = x(1,i)
            idmin = i
         endif
      enddo
 
      end