Folks On close observation made some changes to the fragment of code below on the suspicion that I was not setting null values correctly or passing pointers right so the modified code is now given below but still I get the same error of: ERROR: No null file for <madresult.0>
Please give me some suggestions as I have a deadline approaching. Modified code: MA.resize(bands,rows,cols) for b in range(bands): ofn = "madresult." + str(b) out_fd = Rast_open_new(ofn,DCELL_TYPE) if out_fd < 0: grass.fatal(_("Unable to create raster map <%s>") % ofn) out_rast = Rast_allocate_d_buf() #out_rast = cast(c_void_p(out_rast), ptype) for row_n in range(rows): for col_n in range(cols): #if math.isnan(MAD[b,row_n,col_n]): if (Rast_is_d_null_value(pointer(c_double(MAD[b,row_n,col_n])))): Rast_set_d_null_value(pointer(c_double(out_rast[col_n])),1) else: out_rast[col_n] = MA[b,row_n,col_n] Rast_put_row(out_fd,out_rast,DCELL_TYPE) G_free(out_rast) Rast_close(out_fd) Humble regards On Apr 11, 2011, at 8:25 AM, Sudipta Sarkar wrote: Dear List Users, Please help me solve the following, I am entirely new to the whole Python-GRASS-Ctypes issue so please bear with me. I am trying to develop an application using Python Ctypes hooks to GRASS C libraries. Have done most of the part but getting stuck in the end where i try to write off my output file as GRASS raster. I am giving the relevant part below along with the error I am getting: ptype = POINTER(c_float) MA.resize(bands,rows,cols) for b in range(bands): ofn = "madresult." + str(b) out_fd = Rast_open_new(ofn,FCELL_TYPE) if out_fd < 0: G_fatal_error("Unable to create raster map <%s>", ofn) out_rast = Rast_allocate_buf(FCELL_TYPE) out_rast = cast(c_void_p(out_rast), ptype) for row_n in range(rows): for col_n in range(cols): if math.isnan(MA[b,row_n,col_n]): Rast_set_null_value(out_rast[col_n],1,FCELL_TYPE) else: out_rast[col_n] = MA[b,row_n,col_n] Rast_put_row(out_fd,out_rast,FCELL_TYPE) G_free(out_rast) Rast_close(out_fd) where MA is a numpy.ndarray, bands, rows and cols are all integer type variables and are self explanatory i believe. When it comes to executing the line "Rast_close(out_fd)" I am getting the error: "ERROR: No null file for <madresult.0>" How do I write the null file? I have some experience in developing GRASS raster modules in C and there I never had to write any null file explicitly so whats going wrong over here? Any help from all you GRASS pioneers will be deeply appreciated.
_______________________________________________ grass-dev mailing list grass-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/grass-dev