PecanProject/pecan — pull request #282 by robkooper (2014-12-07 01:04:31+00:00)
Title: integrators lat/lon/time changes from Josh

@jam2767 and @mdietze please can you check this. I took the changes from Josh and looked at the outputs it generated and compared the graphs to the original code. The graphs looks similar except for precipitation_flux and specific_humidity.

For precipitation_flux I checked the new graph with the data from Ameriflux and it follows the same pattern, in the case of the original code the precipitation_flux seemed to be always 0.

For specific_humidity I get a different graph. Looking at the original code it seems there was an error:
```R
rh <- ncvar_get(nc=nc2,varid='RH')
rh.sub <- which(rh > -6999) #select non-missing data
rh.sh <- as.vector(rh.sub/100) #percent to proportion: needed for conversion
rh.sh <- replace(x=rh,list=rh.sub,values=rh.sh) #insert proportion values into RH vector
ta.rh <- ta[rh.sub] # use T coincident with RH
sh.miss <- rh2qair(rh=rh.sh[rh.sub],T=ta.rh) #conversion, doesn't include missvals. was rh2rv
sh <- replace(x=rh,list=rh.sub,values=sh.miss) #insert Kelvin values into vector
sh.var <- ncvar_def(name='specific_humidity',units='kg/kg',dim=list(lat,lon,time),missval= -9999) #define netCDF variable, doesn't include longname and comments
nc = ncvar_add(nc=nc2,v=sh.var,verbose=TRUE) #add variable to existing netCDF file
```

I think the bug sits in `rh.sub <- which(rh > -6999)` which returns the index of those that are >-6999, not the values. Next it takes the index and divides it by 100, not the value. Do I interpret that correctly? And is this indeed a bug in the original code?