title: Calculating min, max, mean, and standard deviation of a large array doesn't return any output
body: <p>I am struggling to calculate the mean, standard deviation, and find the min and max values of a large array in Fortran. There are no errors in my code below, but I am not receiving any values in my output file. Therefore, I believe my code to calculate the mean, standard deviation, and obtain the min and max values is incorrect.</p>
  <p>Background - I first calculated Red NDVI and Green NDVI, which are 2 types of a Normalized Difference Vegetation Indices (NDVI). I calculated the RNDVI and the GNDVI for where seagrass was present in a large AscII file imported from ArcGIS. Now, I am trying to find the minimum and maximum RNDVI and GNDVI. And I am also trying to calculate the mean and standard deviation of these large text files that consists of the different Vegetation Indices (VIs).</p>
  <pre><code>PROGRAM Seagrass
  IMPLICIT NONE
  INTEGER, DIMENSION (2) :: Location, Location1, Location2, Location3, Location4
  REAL, DIMENSION (:,:), ALLOCATABLE :: RNDVI, GNDVI, Seag, Green, Red, Infrared!, n, i
  INTEGER :: NCOL, NROW, CELL, NoData, ROW, COL
  REAL :: XCORD, YCORD, m1, s1, m2, s2
  CHARACTER (LEN=14) :: TEMP
  
  !Read in necessary files
  OPEN(1, FILE = &quot;D:\Fall_2021\Advance_Environmental_Modeling\Lab_6\seag_ascii.txt&quot;, status=&quot;old&quot;) !Read
  OPEN(2, FILE = &quot;D:\Fall_2021\Advance_Environmental_Modeling\Lab_6\red_ascii.txt&quot;, status=&quot;old&quot;) !Read
  OPEN(3, FILE = &quot;D:\Fall_2021\Advance_Environmental_Modeling\Lab_6\infrared_ascii.txt&quot;, status=&quot;old&quot;) !Read
  OPEN(4, FILE = &quot;D:\Fall_2021\Advance_Environmental_Modeling\Lab_6\green_ascii.txt&quot;, status=&quot;old&quot;) !Read
  OPEN(5, file= &quot;D:\Fall_2021\Advance_Environmental_Modeling\Lab_6\Seagrass\RNDVI.txt&quot;, status=&quot;Unknown&quot;)!Write
  OPEN(6, file= &quot;D:\Fall_2021\Advance_Environmental_Modeling\Lab_6\Seagrass\GNDVI.txt&quot;, status=&quot;Unknown&quot;)!Write
  
  
  !Read in Header of files
  READ (1, *) TEMP, NCOL
  READ (1, *) TEMP, NROW
  READ (1, *) TEMP, XCORD
  READ (1, *) TEMP, YCORD
  READ (1, *) TEMP, CELL
  READ (1, *) TEMP, NoData
  
  READ (2, *) TEMP, NCOL
  READ (2, *) TEMP, NROW
  READ (2, *) TEMP, XCORD
  READ (2, *) TEMP, YCORD
  READ (2, *) TEMP, CELL
  READ (2, *) TEMP, NoData
  
  READ (3, *) TEMP, NCOL
  READ (3, *) TEMP, NROW
  READ (3, *) TEMP, XCORD
  READ (3, *) TEMP, YCORD
  READ (3, *) TEMP, CELL
  READ (3, *) TEMP, NoData
  
  READ (4, *) TEMP, NCOL
  READ (4, *) TEMP, NROW
  READ (4, *) TEMP, XCORD
  READ (4, *) TEMP, YCORD
  READ (4, *) TEMP, CELL
  READ (4, *) TEMP, NoData
  
  !Allocation of Variables
  ALLOCATE (Seag(NROW, NCOL))
  ALLOCATE (Green(NROW, NCOL))
  ALLOCATE (Red(NROW, NCOL))
  ALLOCATE (Infrared(NROW, NCOL))
  ALLOCATE (RNDVI(NROW, NCOL))
  ALLOCATE (GNDVI(NROW, NCOL))
  
  !Do loop of readingin files
  DO Row= 1, Nrow
  READ(1,*)(Seag(Row, Col), Col=1, Ncol)
  READ(2,*)(Red(Row, Col), Col=1, Ncol)
  READ(3,*)(Infrared(Row, Col), Col=1, Ncol)
  READ(4,*)(Green(Row, Col), Col=1, Ncol)
  END DO
  
  ! Loop Calculating NDVIs in Datasets
  DO ROW =1 , NROW
  DO COL = 1, NCOL
  IF (Seag(Row, Col)==1) THEN
  RNDVI(ROW,COL) = ((Infrared(ROW,COL)-Red(ROW,COL))*1.0/(Infrared(ROW,COL)+Red(ROW,COL)))
  GNDVI(ROW,COL) = ((Infrared(ROW,COL)-Green(ROW,COL))*1.0/(Infrared(ROW,COL)+Green(ROW,COL)))
  END IF
  END DO
  END DO
  
  !Writing NDVIs to files
  WRITE(5,*)RNDVI
  WRITE(6,*)GNDVI
  
  !Reading in NDVI Files
  DO Row= 1, Nrow
  READ(5,*)(RNDVI(Row, Col), Col=1, Ncol)
  READ(6,*)(GNDVI(Row, Col), Col=1, Ncol)
  END DO
  
  m1= 0.0
  m2=0.0
  
  DO ROW =1 , NROW
  DO COL = 1, NCOL
  IF (RNDVI(Row, Col)/=1) THEN
  m1 = sum(RNDVI)*1.0/(max(1, size(RNDVI))
  !m1 = sum(RNDVI, RNDVI /=0)/(max(1,count(RNDVI /=0)))
  s1 = sqrt(sum(RNDVI**2 )/size(RNDVI) - m1**2 )
  END IF
  END DO
  END DO
  
  DO ROW =1 , NROW
  DO COL = 1, NCOL
  IF (GNDVI(Row, Col)/=1) THEN
  m2 = sum(GNDVI)/size(GNDVI)
  s2 = sqrt(sum(GNDVI**2 )/size(GNDVI) - m2**2 )
  END IF
  END DO
  END DO
  
  WRITE(*,*)m1
  WRITE(*,*)s1
  
  WRITE(*,*)m2
  WRITE(*,*)s2
  
  ! Min &amp; Max Values
  location1 = maxloc(RNDVI, Mask =(Seag == 1))
  location2 = minloc(RNDVI, Mask =(Seag == 1))
  
  location3 = maxloc(GNDVI, Mask =(Seag == 1))
  location4 = minloc(GNDVI, Mask =(Seag == 1))
  
  
  ! Print out the subscripts and correponding NDVI value
  WRITE (*, *) location1, RNDVI(location(1),location(2))
  WRITE (*, *) location2, RNDVI(location(1),location(2))
  
  WRITE (*, *) location3, GNDVI(location(1),location(2))
  WRITE (*, *) location4, GNDVI(location(1),location(2))
  
  STOP
  
  
  END PROGRAM Seagrass
  </code></pre>
  <p>Why am I not getting any output values?</p>