[R] Please help

Pascal Oettli kridox at ymail.com
Wed Jul 4 11:39:29 CEST 2012


Hello,

Following lines are wrong:
> x=dim.def.ncdf("Lon","degreesE",140.0251:146.6751)
> y=dim.def.ncdf("Lat","degreesN",(-31.025):(-38.975))

You have 241 longitudes and 160 latitudes.
lon <- seq(from=140.0251, to=146.6751, length.out=241)
lat <- seq(from=-38.975, to=-31.025, length.out=160)

Regards



----- Mail original -----
De : Jun Chen <chenshong at hotmail.com>
À : r-help at r-project.org
Cc : 
Envoyé le : Mercredi 4 juillet 2012 10h52
Objet : [R] Please help


Dear All,
           I am a research student in environment. I have only little programming knowledge. I am currently doing the last project about rainfall impact on ground water quality in an area. It happens that I have to use R to read rainfall data (3 dimension) from ASC file (*.asc), and then write them into one NCDF file (*.nc).

           I have been working very hard on study R, but I still can not fix the problem. Could someone please as kind as point out that what the problems are in my R script?

         Firstly, this is an example of data in asc file:
                    NCOLS      241

                    NROWS      160

                    XLLCORNER    140.00012207031    

                    YLLCORNER   -39.000000000000    

                    CELLSIZE    0.50000000000000E-01

                    NODATA_VALUE   -99.00000    

                    166.30  160.87  155.23  149.33  143.83  138.52  133.29  128.34  123.76  119.21

                    115.06  110.90  107.22  103.69  100.40   97.29   94.58   92.15   90.00   87.91

                    86.20   84.57   83.22   81.94   81.11   80.38   79.37   78.73   79.70   79.62
          -----------------------------------------------------------------------------------------------------------------------      



          And then this is the script I wrote:

setwd("E:/grid")

#defining dimension

x=dim.def.ncdf("Lon","degreesE",140.0251:146.6751)

y=dim.def.ncdf("Lat","degreesN",(-31.025):(-38.975))

t=dim.def.ncdf("Time","1968-01",1:12,unlim=TRUE)



#setup variable

varmr=var.def.ncdf("mr","mm",list(x,y,t),-99.00,

longname="monthly rainfall")


#create ncdf file

ncnew=create.ncdf("rainfall.nc", varmr)


#read input

files=list.files(pattern=".asc")

mrain=matrix(0:0,0,3)


for(i in files)

{rainfall=data.frame(readAsciiGrid(i))

  mrain=cbind(mrain,rainfall)

}

put.var.ncdf(ncnew, mrain)


close.ncdf(ncnew)

-------------------------------------------------------------------------------

[[elided Hotmail spam]]





Many thanks,
Jun



                          
    [[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list