Hello everyone,
I tried to use "demo.ncvar_put_dmat()" function provided in pbdDEMO to store my own ddmatrix object to a NCDF4 file but I met a problem.
When I called "demo.ncvar_put_dmat()" function, I met the following error message:
Using 2x2 for the default grid size
Error in demo.ncvar_put_2D(nc, varid, vals, verbose = verbose, comm = comm) :
dim(vals) and count are not consistent.
Calls: demo.ncvar_put_dmat -> demo.ncvar_put_2D
Execution halted
I wrote my code following the demo file 'nc4_demo.r'(github page
here). I modified the demo code to store a simple 4*3 matrix . My code is provided as below(also provided in the attachment):
library(pbdDEMO, quietly = TRUE)
library(pbdNCDF4, quietly = TRUE)
# -------------------------------------
# Write and read NetCDF4 file in ddmatrix
# -------------------------------------
### initial grid
init.grid()
if(comm.size() != 4){
comm.stop("This example requries 4 processors.")
}
### divide data into ddmatrix
x <- matrix(c(1,2,3,4,5,6,7,8,9,10,11,12),nrow=4,ncol=3)
dx <- as.ddmatrix(x)
# define dimension and variable
dimRow <- ncdim_def("dimRow","1",vals=seq(1,4))
dimCol <- ncdim_def("dimCol","1",vals=seq(1,3))
var.def <- ncvar_def("Data","1",list(dimRow=dimRow,dimCol=dimCol),NULL)
### parallel write
file.name <- "nc4_dmat.nc"
nc <- nc_create_par(file.name, var.def)
demo.ncvar_put_dmat(nc, "Data", dx)
nc_close(nc)
if(comm.rank() == 0){
ncdump(file.name)
}
finalize()
I ran the program with : mpirun -np 4 Rscript ./my_own_write.r I got the error message before.
Is there something wrong in my own code? or is it a bug?
Thank you for your discussion!
Dale Wang