# MINVAL

### Function Type:

This function works on arrays.

### Function Purpose:

This intrinsic function searches through an entire array ( or just a single dimension depending the options used) for the smallest possible value contained within it. The function will then return this value.

### Required Arguments:

minval(array) "array" is a REAL or INTEGER array

### Optional Arguments:

"marray" evaluates to an array with type LOGICAL having the same shape as "array". This could simply be a LOGICAL array, or it could be the results of a logical comparison of the contents of any array with the same shape as "array" to some criterion. For example, if the following arrays are declared and initialized:
```			real x(5),y(5), minx
logical b(5)
data x/1.,2.4,3.1,-5.2,2./
data y/1.,2.,3.,1.,1./
data b/.t.,.f.,.t.,.f.,.t./
```
and minval is used as such:
```			minx = minval(x,mask=b)
```
Then minx will equal 2.0. This is because minval found the fifth element of "x" to be the smallest value in "x" for which the corresponding element in "b" is true . Logical expressions can be placed in the MASK argument. For instance, using the above defined arrays, the statement:
```			minx = minval(x,mask=x.gt.0)
```
Will search for the smallest positive value contained in "x" and return it to minx. In this case the value would be one. Also, logical arguments can be used with other arrays in the above manner. For instance, the statement:
```			minx = minval(x,mask=y.gt.1)
```
will search out the smallest value of "x" were the corresponding element of "y" is greater than one. In this particular example, the answer would be 2.4.

DIM = ival

This instructs the computer to search over the indicated dimension for the minimum value. You would get the minimum value for each column with "dim = 1" or for each row with "dim= 2". Note that the use of this optional argument implies that the result of the function is itself an array with rank one less than that of the argument "array".

Also, be aware that the argument DIM= works for many other intrinsic functions as well. Using the DIM= argument with other intrinsic functions will have the same effect of collapsing one dimension of the array. For instance, look at the results of using the SUM function and the DIM= argument in the following example.
```		Real x(3,3),y(1:3), z(1:3)
do 100 I = 1,3
do j = 1,3
x(i,j)= I
End do
100 continue
```
Be aware that the above do loop puts values of one in the first row of x, the value of two in the second row and three in the third row.
```		Y = sum(x,dim=2)
Z = sum(x,dim=1)
```
In the first sum, y = (3,6,9) because dim=2 made it sum by rows ( just like dim=2 makes the minval function search for the smallest possible values in each row ). The second sum resulted in z = (6,6,6) because the sum was carried out using the values stored in each column ( again, just like dim=1 on minval forcing it to search by column for the smallest possible value ).
Note: DIM and MASK can be used in conjunction.

### Results:

If the optional argument DIM is not present the result is a scalar with type the same as required argument "array". If DIM is present the result is an array with type the same as required argument "array" and rank one less than that of "array". Note that "dim=n" collapses out the nth dimension of "array". The following array specifications are necessary for the listed uses of minval.
```		real x(5,6,7), xm1(6,7), xm2(5,7), xm3(5,6)
xm1=minval(x,dim=1)
xm2=minval(x,dim=2)
xm3=minval(x,dim=3)
```