mwindow: an interactive fortran-77 program for calculating moving-window statistics

8
Computers & Geosciences Vol. 17, No. 3, pp. 423-430, 1991 0098-3004/91 $3.00 + 0.00 Pnnted in Great Britain. All rights reserved Copyright © 1991 PergamonPresspie MWINDOW: AN INTERACTIVE FORTRAN-77 PROGRAM FOR CALCULATING MOVING-WINDOW STATISTICS MICHAEL R. MURRAY and DALE E. BAKER Soil and Environmental Chemistry Laboratory, The Pennsylvania State University, University Park, PA 16802, U.S.A. (Received 12 February 1990; accepted 7 August 1990) Abstract--An important technique used in exploratory analysis of spatial data is moving-window statistics. In this technique, summary statistics of a spatial variable is determined within local neighbor- hoods (windows) that make up the study site. From these summary statistics, trends and anomalies in local average value and local variability can be examined. This paper presents a FORTRAN-77 program to compute moving-window means and standard deviations with or without window overlap. An example is given and the results are displayed using postplots and scatterplots. Key Words: Moving-window statistics, Exploratory data analysis. INTRODUCTION Exploratory data analysis is an essential first step to modeling spatially correlated data. The objectives of exploratory data analysis are: (1) to help familiarize the investigator with the data; (2) to detect any unusual data values (for example data outliers); and (3) to aid the investigator in deciding whether the variable under study meets the assumptions of the underlying spatial model being used. One important technique used in exploratory analysis of spatial variables is moving-window stat- istics (Isaaks and Srivastava, 1989). Moving-window statistics is simply the determination of summary statistics of spatial data within local neighborhoods (windows) that make up the study site. For purposes of this paper, only the window mean and standard deviation will be considered. Once local data have been assigned to a window and summary statistics calculated, trends and anomalies in both the average values and in variability can be examined. Window statistics that show obvious anomalies in average values and variability can have important practical implications. For example, in the cleanup of soil at a hazardous waste site, areas with large fluctuations in contaminant concentration could hamper the effec- tiveness of a remediation protocol. Window statistics also is useful in providing support for the selection of a particular spatial interpolation model. For example, in many kriging applications the mean and variance are assumed to be constant throughout the study site. By examining window means and standard deviations one can determine whether these assumptions are violated. Because the estimation of a window mean and standard deviation will depend upon the number of samples falling within that window, the selection of a window size should not be arbitrary. A window size which is too small will result in too few data for reliable window mean and standard deviation esti- mation whereas a window size too large may hide local anomalies in the data. Because many spatial studies have a limited number of data points, overlap- ping of windows may be performed in order to obtain enough data points within each window (Journel, 1987). The selection of a window size and deciding whether to overlap windows usually is made by trial and error. Thus, it is desirable to have a computer program which can calculate directly moving-window statistics. The purpose of this paper is to present a menu driven FORTRAN-77 program MWINDOW which calculates the means and standard deviations of moving windows. The main advantage of this program is that the user can calculate quickly window statistics for many window sizes with or without window overlap. THE METHOD OF MOVING-WINDOW STATISTICS The method of moving window statistics is straightforward. A rectangular window size is defined and the window is moved over the data area in increments of the window size or, if overlap is desired, in increments of one-half the window size. All points falling within a window are used for calculating the mean and standard deviation of that window. The window statistics then are attached to the window center coordinates for postplotting or contouring of the window statistics. 423

Upload: michael-r-murray

Post on 25-Aug-2016

214 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: MWINDOW: An interactive FORTRAN-77 program for calculating moving-window statistics

Computers & Geosciences Vol. 17, No. 3, pp. 423-430, 1991 0098-3004/91 $3.00 + 0.00 Pnnted in Great Britain. All rights reserved Copyright © 1991 Pergamon Press pie

MWINDOW: AN INTERACTIVE FORTRAN-77 PROGRAM FOR CALCULATING MOVING-WINDOW STATISTICS

MICHAEL R. MURRAY and DALE E. BAKER Soil and Environmental Chemistry Laboratory, The Pennsylvania State University, University Park,

PA 16802, U.S.A.

(Received 12 February 1990; accepted 7 August 1990)

Abstract--An important technique used in exploratory analysis of spatial data is moving-window statistics. In this technique, summary statistics of a spatial variable is determined within local neighbor- hoods (windows) that make up the study site. From these summary statistics, trends and anomalies in local average value and local variability can be examined. This paper presents a FORTRAN-77 program to compute moving-window means and standard deviations with or without window overlap. An example is given and the results are displayed using postplots and scatterplots.

Key Words: Moving-window statistics, Exploratory data analysis.

INTRODUCTION

Exploratory data analysis is an essential first step to modeling spatially correlated data. The objectives of exploratory data analysis are: (1) to help familiarize the investigator with the data; (2) to detect any unusual data values (for example data outliers); and (3) to aid the investigator in deciding whether the variable under study meets the assumptions of the underlying spatial model being used.

One important technique used in exploratory analysis of spatial variables is moving-window stat- istics (Isaaks and Srivastava, 1989). Moving-window statistics is simply the determination of summary statistics of spatial data within local neighborhoods (windows) that make up the study site. For purposes of this paper, only the window mean and standard deviation will be considered. Once local data have been assigned to a window and summary statistics calculated, trends and anomalies in both the average values and in variability can be examined. Window statistics that show obvious anomalies in average values and variability can have important practical implications. For example, in the cleanup of soil at a hazardous waste site, areas with large fluctuations in contaminant concentration could hamper the effec- tiveness of a remediation protocol. Window statistics also is useful in providing support for the selection of a particular spatial interpolation model. For example, in many kriging applications the mean and variance are assumed to be constant throughout the study site. By examining window means and standard deviations one can determine whether these assumptions are violated.

Because the estimation of a window mean and standard deviation will depend upon the number of

samples falling within that window, the selection of a window size should not be arbitrary. A window size which is too small will result in too few data for reliable window mean and standard deviation esti- mation whereas a window size too large may hide local anomalies in the data. Because many spatial studies have a limited number of data points, overlap- ping of windows may be performed in order to obtain enough data points within each window (Journel, 1987).

The selection of a window size and deciding whether to overlap windows usually is made by trial and error. Thus, it is desirable to have a computer program which can calculate directly moving-window statistics. The purpose of this paper is to present a menu driven FORTRAN-77 program MWINDOW which calculates the means and standard deviations of moving windows. The main advantage of this program is that the user can calculate quickly window statistics for many window sizes with or without window overlap.

THE METHOD OF MOVING-WINDOW STATISTICS

The method of moving window statistics is straightforward. A rectangular window size is defined and the window is moved over the data area in increments of the window size or, if overlap is desired, in increments of one-half the window size. All points falling within a window are used for calculating the mean and standard deviation of that window. The window statistics then are attached to the window center coordinates for postplotting or contouring of the window statistics.

423

Page 2: MWINDOW: An interactive FORTRAN-77 program for calculating moving-window statistics

424 M . R . MURRAY and D. E. B,rdm

PROGRAM DESCRIPTION

MWINDOW will calculate the mean and standard deviation of data points falling within individual windows over a defined area. An input data f-de is read by MWINDOW using free format. The data file must contain a separate column for the x and y coordinates and for the variable. The order of the columns does not matter because MWlNDOW will ask the user for coordinate and variable locations. All columns must be separated by either a space or a comma. An example of a session with MWlNDOW is given in Table 1.

As shown in Table 1, the user specifies the maxi- mum and minimum boundary coordinates for the site. In addition, the user is prompted to input the window size in the x and y directions. MWINDOW only will calculate windows that fall completely within the specified x and y boundaries. For example, given the x and y coordinate length of 100 x 25 m,

respectively, a 25 x 25 m window size will result in a

total of 4 windows for the no overlap option and 7 windows for the overlap option.

The output file created by MWINDOW contains the centered x and y coordinates of each window, the number of data points within each window, and the mean and standard deviation of each win- dow. In addition, the output file contains the heading needed for the use with U.S. EPA public domain Geostatistical Environmental Assessment Software (U.S. EPA, 1988). The scatter plot and post- plot programs in GEOEAS can be used to evaluate the moving window statistics. However, the file heading can be changed easily, via a file editor (for example EDLIN) or word processor, for import into other software packages that accept ASCII formatted files.

The program MWINDOW was developed on an IBM XT compatible computer using a Microsoft FORTRAN-77 compiler. To the best of the

Table 1. Example showing how to run program

c:> MWINDOW

*********************************************

MWINDOW A PROGRAM TO CALCULATE SUMMARY STATISTICS

OF WINDOWS WITHIN A DEFINED AREA. YOU WILL NEED AN INPUT FILE WITH X,Y,VAR COLUMNS

THE DATA IS READ IN USING FREE FORMAT *********************************************

ENTER THE NAME OF THE DATA FILE: A:PB.DAT ENTER THE COLUMN NUMBER FOR THE X AXIS:

1 ENTER THE COLUMN NUMBER FOR THE Y AXIS:

2 ENTER THE COLUMN NUMBER FOR THE VARIABLE:

3 THE NUMBER OF DATA FOUND = 180 ENTER THE MINIMUM X-COORDINATE VALUE:

240 ENTER THE MAXIMUM X-COORDINATE VALUE:

3500 ENTER THE MINIMUM Y-COORDINATE VALUE:

230 ENTER THE MAXIMUM Y-COORDINATE VALUE:

3500 ENTER THE WINDOW SIZE IN THE X-DIRECTION:

1630 ENTER THE WINDOW SIZE IN THE Y-DIRECTION:

1635

DO YOU WANT WINDOWS TO OVERLAP (Y/N)? Y THE NUMBER OF WINDOWS FOR OVERLAP OPTION: DO YOU WISH TO CHANGE WINDOW SETTINGS (Y/N)?

N ENTER THE NAME OF THE OUTPUT FILE:

A:MW.DAT 1055.0 1047.5 45. 196.287 1870.0 1047.5 53. 198.813

9.000000

371.9047 343.5084

DATA BEING WRITT~ TO O~PUT FILE: A:MW,DAT DO You WISH TO EXIT THIS PROG CY/N>?

Y STOP - Program terminated

Page 3: MWINDOW: An interactive FORTRAN-77 program for calculating moving-window statistics

Interactive program for calculating moving-window statistics 425

authors' knowledge the program adheres to ANSI FORTRAN-77 standard.

EXAMPLE

Moving-window statistics is illustrated using soil lead (Pb) data collected in the vicinity of a smelter (Isaaks, 1985). A postplot of the soil Pb concen- tration (mg/kg) for the study site is shown in Figure 1. As expected, the concentration of Pb is greatest in the immediate vicinity of the smelter (Fig. 1) and de- creases with distance from the stack. Note, however, that several apparent "outliers" exist in the data (for example at casting 3482 and northing 2306 m a Pb concentration of 10,400 mg/kg was determined).

Window means and standard deviations for Pb at a 815 x 817.5 m window size with window overlap is shown in Figure 2. There were a total of 49 windows, 39 of which contained 10 or more samples. Any window that contained less than 10 samples was removed prior to plotting since it was felt that summary statistics with less than 10 data points may be unreliable. It is evident from Figure 2 that the window means and standard deviations are not con-

stant over the rite. Generally, the window mean and standard deviation increased in the vicinity of the smelter. A scatter plot of window mean vs standard deviation reveals that the window standard deviation increases proportionally with increasing window mean (Fig. 3). Increasing standard deviation with increasing mean generally is taken as evidence for heteroscedasticity (Journel, 1977). Note, however, that two window data values have unusually high standard deviations compared to the rest of the window data, Examining the postplot of the window statistics (Fig. 2), these two points are located in the northeast section of the site (3093 m casting and 2638 m northing; 3093 m casting and 2274 m nor- thing). The high standard deviation can be attributed, in part, to the single sample point with a soil Pb concentration of 10,400 mg/kg (Fig. 1). For further analysis of this data set, moving-window statistics could be performed on the data set after removing this apparent outlier. Furthermore, data transform- ations (for example natural logarithm of the soil lead concentration) and the use of different window sizes could be performed to see if the window statistics change.

486

3228

2955

2683

2410

~' 2138

,865 }: ° Z

~. 1593 0 z

1320

1048

503

23O 2 4 0

384 1~9 Rg=~ 110 * * * "

2950 129 98 3,5 134 76 • * ..303 674 422

161 169 , 52 * 234 99 185 121

201

164 108 275 129 * 92 1060 • * 230 432 * • 84 i * =l, *

153 122 291 4-35 240 4230 • . * , * , 1790 237 7

1,31 2,8, ,68o 6% 9 * 2130 3020 1 140, , , 320,

127 771 8 385O 159 4.4 . . 8 5 1 7 * 121 352 = , 584 62 234

2 81~'0 %0-,- . , . * • . • 80

104 160 * 574 617 , , , 323 1590 792 575 872 • 2460 * * * ,

• 1 7 7 * * * * 93 *

152 13(}' 459 100 342 92 , 106133 35 • 1 6 7 * , • * * * .=

78 357 , 205 150 106 393 207 52 27

, . 4 4 . 1 4 7 * *

71 4g 6 , 226 123 150 63 211 78 • 238 ,

• 7 3 * . * . * 1= . *

53 39 158 24 50 39 306 • 274 • , , • 77, * 5 2 *

101 * 102 , 58 41

• 25 25 47 * 1 7 0 . * * * * 8 0

51 35

63 ' 42 ~4 [ [ I [ t [ [ ] * I t I j 5 9 I I i * ....I [ ] 1

5 1 2 7 8 3 1 0 5 5 1 3 2 7 1 8 7 0 2 1 4 2 2 4 1 3 2 6 6 5

at

2190

3500

254 27 166 720 * 357 522

• * 271 202 * * 595 212

182

396 538 * *

80 6~ 3

1598 EASTINC (METERS)

Figure 1. Postplot of soil lead concentrations (mg/kg) near smelter. Data are taken from lsaaks (1984). Smelter is located at easting of 1905 m and northing 1905 m.

74 10 ~0

117 694 s

59 71 *

4~3

1~1 238

76 , 274

232 200

I I I I 2957 3 2 2 8 3500

Page 4: MWINDOW: An interactive FORTRAN-77 program for calculating moving-window statistics

426 M . R . MugRAv and D. E. B^KEg

3500

3228

2955

2683

2410

~ ' 2 1 3 8 w

1865

Z

1593 o z

1320 -

1048 -

775 -

503 -

127 372

70 730

546

613

! 144 264 863 1615 J i =

' 72 355 1243 1379

279 286 932 1875

616 361 1218 1319

I 340 214 473 1058

661 193 658 1225

445 1340 683 2917

1387 1145

1211 3079

909 410

1114 283

241 200 329 448 305 263

212 177 644 677 181 254

136 120 105 155 202 168 160

104 84 55 135 136 109 96

76 80 63 117 176 ..t. t . , , .*

44 59 45 104 107

230 ,1 I I I ,I , I I l I I I , I I 1 I I I I I I I l J 240 512 783 1055 1327 1598 1870 2142 2413 2685 2957 3228 3500

EASTING (METERS)

Figure 2. Postplot of moving-window statistics using 815 x 815.5 m window size with overlap. Window mean is plotted above " , " , and standard deviation below.

W I N D O W 8 ~ N D A R D D E V I ~ I O N 3500

3000

2500

2000

1500

1000

500

0 0 50O 1000 1500 2000

WINDOW MEAN

Figure 3. Scatterplot of window mean vs window standard deviation for 815 × 815.5 m window size with overlap.

CONCLUSIONS

A standard F O R T R A N - 7 7 program has been de- veloped for calculating moving-window statistics. The program allows the user to interactively select the window size as well as an option for window

overlap. Moving window statistics is a useful tool in exploratory data analysis.

REFERENCES

lsaaks. E., 1984, Risk qualified mappings for hazard- ous waste sites: a case study in distribution-free

Page 5: MWINDOW: An interactive FORTRAN-77 program for calculating moving-window statistics

Interactive program for calculating moving-window statistics 427

geostatistics: unpubl, masters thesis, Stanford Univ., 85p.

Isaaks, E. H., and Srivastava, R. M., 1989, Ap- plied geostatistics: Oxford Univ. Press, New York, 544 p.

Journel, A. G., 1987, Geostatistics for the environmental sci. ences---an introduelion: EPA Project No. CR 811893, 135 p.

U.S. Environmental Protection Agency, 1988, GEOEAS (Geostatistical Environmental Assessment Software) User's Guide EPA 600/4-88/033, 133p.

APPENDIX

Program MWINDOW

C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C C

MWINDOW: A MOVING WINDOW STATISTICS PROGRAM *******************************************

INPUT :

PRIOR TO RUNNING MWINDOW A DATA FILE MUST BE CREATED. COLUMNS MUST BE SEPARATED BY EITHER A SPACE OR A COMMA. AN EXAMPLE OF A DATA FILE WHERE X IS IN COLUMN 1, Y IS IN COLUMN 2, AND THE VARIABLE OF INTEREST IS IN COLUMN 3 LOOKS LIKE:

100.0 I00.0 23.4 150.0 150.0 21.4 154.2 150.0 34.3

OUTPUT :

AN OUTPUT FILE IS CREATED IN STANDARD ASCII CONTAINING THE NECESSARY LINE HEADINGS FOR FILE IMPORT INTO US EPA'S GEOSTATISTICAL ENVIRONMENTAL ASSESSMENT SOFTWARE (GEOEAS). FOLLOWING LINE 7 THE OUTPUT FILE CONTAINS 5 COLUMNS OF DATA:

COLUMN 1 = X-COORDINATE OF EACH WINDOW COLUMN 2 = Y-COORDINATE OF EACH WINDOW COLUMN 3 = NUMBER OF DATA POINTS IN EACH WINDOW COLUMN 4 = ARITHMETIC MEAN OF EACH WINDOW COLUMN 5 = STANDARD DEVIATION OF EACH WINDOW

PARAMETERS

NDIM MUST BE AS LARGE OR LARGER THAN THE NUMBER OF DATA. NMW MUST BE AS LARGE OR LARGER THAN THE NUMBER OF WINDOWS.

PARAMETER (NDIM=500,NMW=500)

AUTHORS: M. R. MURRAY AND DALE E. BAKER DATE: JANUARY 1990

REAL X(NDIM), Y(NDIM), VR(NDIM), B(20), XMW(NMW) REAL YMW(NMW) CHARACTER DATAFL*20, SUMFL*20 LOGICAL FREE

5 WRITE(*,100)

100 * * - - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * / / , ' m q I N D O W ' * /,' A PROGRAM TO CALCULATE SUMMARY STATISTICS ' * /,' OF WINDOWS WITHIN A DEFINED AREA. YOU WILL NEED ' * /,' AN INPUT FILE WITH X,Y,VAR COLUMNS ' * /,' THE DATA IS READ IN USING FREE FORMAT ' * //,' *************************************************** ',//)

C C FIND OUT WHERE DATA FILE IS LOCATED: C

WRITE(*,*)' ENTER THE NAME OF THE DATA FILE:' READ(*,200)DATAFL OPEN(1,ERR=10,FILE-DATAFL,STATUS-'OLD') GO TO 20

10 WRITE(*,*)' THE FILE ',DATAFL,'DOES NOT EXIST' STOP

Page 6: MWINDOW: An interactive FORTRAN-77 program for calculating moving-window statistics

428 M. R. MURRAY and D. E. BAKER

C C DEFINE THE COORDINATE AND VARIABLE COLUMNS IN DATA FILE: C 20 WRITE(*,*)' ENTER THE COLUMN NUMBER FOR THE X AXIS:'

READ(*,*)ICOLX WRITE(*,*)' ENTER THE COLUMN NUMBER FOR THE Y AXIS:' READ(*,*)ICOLY WRITE(*,*)' ENTER THE COLUMN NUMBER FOR THE VARIABLE:' READ(*,*)ICOLVR

200 FORMAT(A20) C C READ IN COORDINATE AND VARIABLE DATA: C

ZNULL = -1. NCOL=MAX0(ICOLY,ICOLX,ICOLVR) NT=0

30 NT=NT+I READ(I,*,END=31) (B(J),J=I,NCOL)

VR (NT) =B (ICOLVR) IF(VR(NT).EQ.ZNULL)THEN NT=NT-I GO TO 30

END IF X(NT)=B(ICOLX) Y(NT)=B(ICOLY)

GO TO 30 31 NT=NT-1

WRITE(*,*)' THE NUMBER OF DATA FOUND = ',NT CLOSE ( i )

C C CHECK NDIM C

IF(NT.GT.NDIM) THEN WRITE(*,*) ' ERROR: NUMBER OF DATA > NDIM' WRITE(*,*)' CHANGE NDIM STATEMENT IN MWINDOW.FOR' STOP

END IF C C DEFINE SITE AND WINDOW SIZE C 40 WRITE(*,*) ENTER THE MINIMUM X-COORDINATE VALUE:'

READ(*,*)XMIN WRITE(*,*) ENTER THE MAXIMUM X-COORDINATE VALUE:' READ(*,*)XMAX WRITE(*,*) ENTER THE MINIMUM Y-COORDINATE VALUE:' READ(*,*)YMIN WRITE(*,*) ENTER THE MAXIMUM Y-COORDINATE VALUE:' READ(*,*)YMAX WRITE(*,*) ENTER THE WINDOW SIZE IN THE X-DIRECTION:' READ(*,*) XWIND WRITE(*,*) ENTER THE WINDOW SIZE IN THE Y-DIRECTION:' READ(*,*) YWIND

C C CALCULATE THE NUMBER OF WINDOWS IN EACH DIRECTION C AND THE TOTAL NUMBER OF WINDOWS C

XLENGTHsXMAX-XMIN YLENGTHmYMAX-YMIN ZNWX-XLENGTH/XWIND ZNWY-YLENGTH/YWIND ZNWXO-(ZNWX*2)-I ZNWYO-(ZNWY*2)-I NWX-INT(ZNWX) NWY-INT(ZNWY) NWXO-INT(ZNWXO) NWYO-INT(ZNWYO) WTOTAL,'NWX*NWY WOTO=NWXO*NWYO

C C WRITE WINDOW INFORMATION C

WRITE(*,*)' WRITE(*,*)' DO YOU WANT WINDOWS TO OVERLAP (Y/N)? ' READ(*,'(BN,A)')IOVER IF(IOVER.EQ.'Y'.OR.IOVER.EQ.'y') THEN WRITE(*,*)' THE NUMBER OF WINDOWS FOR OVERLAP OPTION: ELSE WRITE(*,*)' THE NUMBER OF WINDOWS: ',WTOTAL END IF

',WOTO

Page 7: MWINDOW: An interactive FORTRAN-77 program for calculating moving-window statistics

C C C

C

Interactive program for calculating moving-window statistics

CHECK NMW

IF (NMW.LT.WTOTAL.OR.NMW.LT.WOTO) THEN WRITE(*,*) ' ERROR: NUMBER OF WINDOWS • NMW' WRITE(*,*) ' CHECK NMW STATEMENT IN MWINDOW.FOR' STOP ENDIF

WRITE(*,*)' DO YOU WISH TO CHANGE WINDOW SETTINGS (Y/N)? ' READ(*, ' (BN, A) ' ) IFLAG IF(IFLAG.EQ.'Y'.OR.IFLAG.EQ.'y,) THEN GO TO 40 END IF

C C CREATE OUTPUT FILE C

WRITE(*,*) ' ENTER THE NAME OF THE OUTPUT FILE:' READ (*, 200) SUMFL OPEN ( 2, FILE=SUMFL) WRITE (2,300) SUMFL

300 FORMAT(A20,/,'5',/,'X',/,'Y',/,'NO. IN WINDOW',/ • , ' MEAN ' ,/, ' VARIANCE ' )

C C INITIALIZE THE WINDOW COORDINATES TO ZERO: C

DO 15 I=l, (NWXO+I) 15 XMW(I)=0.0

DO 25 I=1, (NWYO+I) 25 YMW (I) =0.0

XMW (0) =XMIN YMW ( 0 ) =YMIN

C C CALCULATED COORDINATES FOR WINDOW CENTER C

XWINDO=XWIND/2 YWINDO=YWIND/2 DO 35 I=1, (NWXO+I)

35 XMW ( I ) =XMW ( I- i) +XWINDO DO 45 I=1, (NWYO+I)

45 YMW (I) =YMW (I-1) +YWINDO C

IF ( IOVER. EQ. ' Y '. OR. IOVER. EQ. ' y ' ) THEN GO TO 60 ELSE GO TO 51 END IF

C C CALCULATE WINDOW MEANS AND STANDARD DEVIATION FOR NO OVERLAP: C 51 DO 55 I=2, (NWYO+I),2

DO 65 J=2, (NWXO+I) ,2 AX=XMW (J-l) AY=YMW (I-l) SUM=O. 0 COUNT=0.0 ZSQR=0.0 ZSD=0.0

DO 75 K=I,NT IF(X(K) .GE.XMW(J-2) .AND. X (K). LE.XMW(J) .AND.

• Y (K) • GE. ¥MW (I-2) .AND. Y (K). LE. YMW (I)) THEN SUM=SUM+VR (K) COUNT=COUNT+I. 0 ZSQR=ZSQR+VR (K) **2

75 END IF IF (COUNT. EQ. 0.0) THEN

GO TO 65 ELSE ZSS,.ZSQR- (SUM**2 / COUNT) IF(COUNT.EQ.I.0) THEN ZVAR=0.0 ELSE ZVAR-ZSS/(COUNT-I) ZSD~"SQRT (ZVAR) END IF ZMEAN=SUM/COUNT

C C WRITE OUTPUT FOR WINDOWS FOR NO OVERLAP C

429

Page 8: MWINDOW: An interactive FORTRAN-77 program for calculating moving-window statistics

430 M. R. MURRAY and D. E. BAF~ER

WRITE (*, 500) AX, AY, COUNT, ZMEAN, ZSD WRITE (2,500) AX, AY, COUNT, ZMEAN, ZSD

500 FORMAT(2(2X,F10.2),2X,F4.0,2(2X,F12.4)) C

END IF 65 CONTINUE 55 CONTINUE

WRITE(*,*)' DATA HAS BEEN WRITTEN TO OUTPUT FILE: ',SUMFL 90 CLOSE(2 }

WRITE(*,*)' DO YOU WISH TO EXIT THIS PROGRAM (Y/N)? ' READ(*,' (BN,A) ' ) IEXIT IF (IEXIT.EQ.'Y'.OR.IEXIT.EQ.'y') THEN GO TO 80 ELSE GO TO 5 END IF

C C CALCULATE WINDOW MEAN AND VARIANCE WITH OVERLAPS C

60 DO 85 I..1, (NWYO) DO 95 J=l, (NWXO)

AX,-XMW (J) AY,,YMW ( I ) SUM..0.0 COUNT-0.0 ZSQR-0.0 ZSD-0.0

DO 105 K=I,NT IF(X(K) .GE. XMW(J-I) .AND. X(K) .LE. XMW(J+I) .AND.

* Y(K).GE.YMW(I-I).AND.Y(K).LE.YMW(I+I)) THEN SUM-SUM+VR (K) COUNT..COUNT+I. 0 ZSQR=ZSQR+VR (K) **2

105 END IF IF (COUNT. EQ. 0.0) THEN

GO TO 95 ELSE ZSS..ZSQR- ( SUM**2 / COUNT) IF (COUNT. EQ. 1. O) THEN ZVAR..0.0

ELSE ZVAR-ZSS / (COUNT-I) ZSD=SQRT (ZVAR) END IF ZMEAN=SUM/COUNT

C C WRITE OUTPUT FOR WINDOWS HAVING OVERLAP C

WRITE (*, 500) AX, AY, COUNT, ZMEAN, ZSD WRITE ( 2,500 ) AX, AY, COUNT, ZMEAN, ZSD

C END IF

95 CONTINUE 85 CONTINUE

WRITE(*,*)' DATA HAS BEEN WRITTEN TO OUTPUT FILE: ',SUMFL GO TO 90

80 STOP END