Hello,

I am trying to come up with a routine to calculate a rolling mean and
standard deviation for three parameters stored in a NetCDF file.  The NetCDF
file contains 10 years of daily records for each of the three parameters,
and I need the statistics for each of the three parameters.

Below I include some code illustrating what I've done so far. Obviously this
approach does not get at the problem. It loops thru the data, to get to the
daily data, but stops short of trying to get the running mean/standard
deviation, an assignment that came after I developed the approach shown
here.

Where should the rolling mean and standard deviation functions be integrated
in the script, and what recommendations - approach can you offer to
accomplish this task.

I am running this on a Windows 7 machine with R 2.12.2
Thanks for taking the time to help.

Steve

--------------------------------------------------------------------------------------------------------------------
setwd("C:\\Woodstorks")
getwd()


library(tis)     #  includes function for leap year
library(ncdf)

 woodstorks <- open.ncdf("WoodStork_Eden_2000_2009.nc")

 print(woodstorks)

  print(v2)

# next two lines create index values for temporal sequences.
 DaysToMonth365 <- c(0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334,
365)
 DaysToMonth366 <- c(0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335,
366)

Lyear <- isLeapYear(2000:2009) #  returns boolean TRUE FALSE vector for
years in sequence


#  next function is used latter in script see line 50
  processMonth<-function(x){
        print(x)
      }

 start_year<- 1999

# initiates 1 year before to capture December of correct year, next line
uses the for loop to run thru
# the number of years. Here 3 is used to limit the number used in a testing
mode.

   for(t in 1:3) {
   currentYear = start_year + t
   leapYear <- isLeapYear(currentYear:currentYear) #  returns boolean vector
TRUE FALSE for years in sequence
   #print(leapYear)
    Days<-DaysToMonth365
          if(leapYear){
             Days<-DaysToMonth366
           }
      print(Days)
      data <- array(data, dim = c(Days[1], 405, 265))
         for(d in 1: 226) {
               for(y in 1: 405) {
                 for(x in 1:287) {
                      Day = 1
                      counter <- 2  # first element in array
                    #print(paste("Day = ", d))
                   if(d >= Days[counter]) {
                       counter <- counter + 1
                       #print(paste("here = ", t))
                       processMonth(data)
                       data <- array(data, dim = c(Days[1], 405, 265))
                        Day = 1
                        print(Day)
                     }
                       else
                   {
                   index<-c(x,y,d,t)
                   count<-c(1,1,1,1)
                   temp<-  get.var.ncdf(woodstorks, v2, start=index, count =
count)
                   i <- (d*405*287) + (y*287) + x #map 3d to 1dimension
                   data[i] = temp[1]
                   #print(data[i])
                   Day <- Day + 1
                   print(Day)
                  }
               }
           }
         }
      }

	[[alternative HTML version deleted]]

