<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 14px;">Dear List Users,</span></font><div><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 14px;"><br></span></font></div><div><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 14px;">Please help me solve the following, I am entirely new to the whole Python-GRASS-Ctypes issue so please bear with me. </span></font></div><div><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 14px;"><br></span></font></div><div><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 14px;">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:</span></font></div><div><br></div><div><div> <font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 16px;"> ptype = POINTER(c_float)</span></font></div><div><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 16px;"> MA.resize(bands,rows,cols)</span></font></div><div><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 16px;"> for b in range(bands):</span></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 16px;">        </span></font></span><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 16px;">ofn = "madresult." + str(b)</span></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 16px;">        </span></font></span><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 16px;">out_fd = Rast_open_new(ofn,FCELL_TYPE)</span></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 16px;">        </span></font></span><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 16px;">if out_fd < 0:</span></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 16px;">        </span></font></span><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 16px;"> G_fatal_error("Unable to create raster map <%s>", ofn)</span></font></div><div><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 16px;"> </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 16px;">        </span></font></span><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 16px;">out_rast = Rast_allocate_buf(FCELL_TYPE)</span></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 16px;">        </span></font></span><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 16px;">out_rast = cast(c_void_p(out_rast), ptype)</span></font></div><div><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 16px;"> </span></font><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 16px;">        </span></font></span><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 16px;">for row_n in range(rows):</span></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 16px;">        </span></font></span><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 16px;"> for col_n in range(cols):</span></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 16px;">                </span></font></span><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 16px;">if math.isnan(MA[b,row_n,col_n]):</span></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 16px;">                </span></font></span><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 16px;"> Rast_set_null_value(out_rast[col_n],1,FCELL_TYPE)</span></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 16px;">                </span></font></span><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 16px;">else:</span></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 16px;">                </span></font></span><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 16px;"> out_rast[col_n] = MA[b,row_n,col_n]</span></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 16px;">        </span></font></span><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 16px;"> Rast_put_row(out_fd,out_rast,FCELL_TYPE)</span></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 16px;">        </span></font></span><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 16px;">G_free(out_rast)</span></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 16px;">        </span></font></span><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 16px;">Rast_close(out_fd)</span></font></div><div><span class="Apple-tab-span" style="white-space:pre"><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 14px;">        </span></font></span></div></div><div><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 14px;">where MA is a numpy.ndarray, bands, rows and cols are all integer type variables and are self explanatory i believe. </span></font></div><div><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 14px;"><br></span></font></div><div><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 14px;">When it comes to executing the line "Rast_close(out_fd)" I am getting the error: "ERROR: No null file for <madresult.0>"</span></font></div><div><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 14px;"><br></span></font></div><div><font class="Apple-style-span" size="4"><span class="Apple-style-span" style="font-size: 14px;">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. </span></font></div></body></html>