Adolf STIPS
2010-Jun-16 15:53 UTC
[R] Help asked for automated generation of ncdf variables
Hi, I'm using the "ncdf" library for creating ncdf files. But I need to create about 100 variables per file (e.g. single rivers), So I do not like to create each variable separately. Unfortunately I found no way to make this work, as I'm unable to create a correct list of class "var.ncdf". ###code piece river=list(mode='var.ncdf', length=nriv) #class(river)="var.ncdf" for ( iriv in 1:nriv) { nam=paste('r',iriv, collapse=NULL,sep="") riv= var.def.ncdf(nam,"m**3/s",d1,msvf,longname=names[iriv],prec="single") #class(river[iriv]) ="var.ncdf" river[iriv] = riv } ncw=create.ncdf(wfile,list(river)) ###This is failing by warning first (which I do not understand): 1: In river[iriv] = riv : number of items to replace is not a multiple of replacement length 2: In river[iriv] = riv : number of items to replace is not a multiple of replacement length ... ###And finally with following error: Error in var.add.ncdf(nc, vars[[ivar]], verbose = verbose, indefine = TRUE) : var.add.ncdf: passed var NOT of class var.ncdf! The second arg to var.add.ncdf must be the return value from a call to var.def.ncdf ### Or folling error if class(river)="var.ncdf" is not commented: Error in 1:nd : argument of length 0 Does anybody know how to achieve this correct (how to create a correct list of class "var.ncdf"?) that would be understood by create.ncdf (I really tried many different things) Thanks for any hints, Adolf ------------------------------------------------ Adolf Stips (new email: adolf.stips at jrc.ec.europa.eu) Global Environment Monitoring unit CEC Joint Research Centre, TP 272 I-21027 Ispra, Italy Tel: +39-0332-789876 Fax: +39-0332-789034 I know that I do not know, but even that not for sure! ------------------------------------------------ "The views expressed are purely those of the writer and may not in any circumstances be regarded as stating an official position of the European Commission."
David Pierce
2010-Jun-29 15:57 UTC
[R] Help asked for automated generation of ncdf variables
> Date: Wed, 16 Jun 2010 17:53:56 +0200 > From: "Adolf STIPS" <adolf.stips at jrc.ec.europa.eu> > > Hi, > > I'm using the "ncdf" library for creating ncdf files. > But I need to create about 100 variables per file (e.g. single rivers), > So I do not like to create each variable separately. > > Unfortunately I found no way to make this work, as I'm unable to create a > correct list of class "var.ncdf".Hello, the var.def.ncdf() call returns an object of class var.ncdf. Since objects are lists, you can't assign them to arrays. However, you can easily assign them to other lists. So instead of this:> riv> var.def.ncdf(nam,"m**3/s",d1,msvf,longname=names[iriv],prec="single") > #class(river[iriv]) ="var.ncdf" > river[iriv] = riv > } > > ncw=create.ncdf(wfile,list(river))Try something this: river = list()> riv> var.def.ncdf(nam,"m**3/s",d1,msvf,longname=names[iriv],prec="single") > river[[iriv]] = riv > } > > ncw=create.ncdf(wfile,river)Regards, --Dave