Sorry for the unnecessary request. I should have just looked at the code for
gridwind.gx.
I did, but I tried to do it in a dll and the GridWind2_IMU call in the
following code gave me the following
error.

"GridWind_IMU : Invalid MDF file handle"

Any ideas as to why? I know I can do the same with just a gx but I'd like to
know why this does not work.


extern "C" __declspec(dllexport)
long __cdecl _CreateObsGrid(void *pGS)
{
    AFX_MANAGE_STATE(AfxGetStaticModuleState());

    double rXmin,rXmax,rYmin,rYmax,x0,y0,x1,y1,z0,z1,zm,zdev;
    double dDx,dDy,dXo,dYo,dRot,dBase,dMult;
    long   lNX,lNY,lKX,lType;
    long EMap, hImg, View, hIPJ, Map;
    char str[255];
    long ne,nd;

    EMap = App_Current_EMAP(pGS);
    if (iCheckError_SYS(pGS)) goto GEO_EXIT;
    Map = App_Lock_EMAP(pGS, &EMap);
    if (iCheckError_SYS(pGS)) goto GEO_EXIT;
    View = Create_MVIEW(pGS, &Map,"*data",_l(MVIEW_READ));
    if (iCheckError_SYS(pGS)) goto GEO_EXIT;
    hIPJ = Create_IPJ(pGS);
    if (iCheckError_SYS(pGS)) goto GEO_EXIT;
    GetIPJ_MVIEW(pGS, &View, &hIPJ);
    if (iCheckError_SYS(pGS)) goto GEO_EXIT;
    Destroy_MVIEW(pGS, &View);
    if (iCheckError_SYS(pGS)) goto GEO_EXIT;
    App_UnLock_EMAP(pGS, &EMap);
    if (iCheckError_SYS(pGS)) goto GEO_EXIT;
    
    App_iSetCurrentView_EMAP(pGS, &EMap,"data");
    if (iCheckError_SYS(pGS)) goto GEO_EXIT;
    rXmin=rXmax=rYmin=rYmax=0.0;

    AfxMessageBox("Specify Area...");
    if (App_iGetBox_EMAP(pGS, &EMap,"Specify
Area...",&rXmin,&rYmin,&rXmax,&rYmax)) {
        AfxMessageBox("Did not get box!", MB_ICONSTOP, NULL);
        return(0);
    }

    if (iCheckError_SYS(pGS)) goto GEO_EXIT;
    {
        static char BASED_CODE szFilter[] = "Grid Files(*.grd)|*.grd|All
Files (*.*)|*.*||";
                
        CFileDialog getFile(TRUE, NULL, NULL, OFN_HIDEREADONLY , szFilter,
theApp.m_pMainWnd);
        getFile.m_ofn.lpstrTitle = "Open corresponding grid file...";
        
        if (getFile.DoModal() != IDOK) return(0);
        
        
        CFileDialog putFile(FALSE, NULL, NULL, OFN_HIDEREADONLY , szFilter,
theApp.m_pMainWnd);
        putFile.m_ofn.lpstrTitle = "Save output grid as...";
        
        if (putFile.DoModal() != IDOK) return(0);
        
 
GridStat_IMU(pGS,getFile.GetPathName(),&lType,&lNX,&lNY,&dDx,&dDy,&lKX,&dXo,
&dYo,&dRot,&dBase,&dMult);
        if (iCheckError_SYS(pGS)) goto GEO_EXIT;
        
        if (dRot!=0.0) {
            AfxMessageBox("Non-zero rotation of input grid", MB_ICONSTOP,
NULL);
            return(0);
        }
        
        
        x0 = dXo;
        while (x0<=rXmin) x0 += dDx;
        x0 -= dDx;
        
        y0 = dYo;
        while (y0<=rYmin) y0 += dDy;
        y0 -= dDy;
        
        x1 = x0;
        while (x1<rXmax) x1 += dDx;
        
        y1 = y0;
        while (y1<rYmax) y1 += dDy;
        
        sprintf(str,"Extents: Xmin %g %g, Xmax %g %g, Ymin %g %g, Ymax %g
%g", rXmin,x0, rXmax,x1,rYmin,y0, rYmax,y1);
        AfxMessageBox(str);
        GridStatExt_IMU(pGS, getFile.GetPathName(), _l(IMU_STAT_FORCED_YES),
&ne, &nd, &z0, &z1, &zm, &zdev);
        if (iCheckError_SYS(pGS)) goto GEO_EXIT;
        if (hIPJ == 0) {
            hIPJ = Create_IPJ(pGS);
            GetIPJ_IMG(pGS, &hImg, &hIPJ);
        }
        hImg = CreateFile_IMG(pGS, _l(GS_FLOAT), getFile.GetPathName(),
_l(IMG_FILE_READONLY));
        if (iCheckError_SYS(pGS)) goto GEO_EXIT;
        if (dDy>dDx)
            Inherit_IMG(pGS, &hImg, &hIPJ, &dDx);
        else Inherit_IMG(pGS, &hImg, &hIPJ, &dDy);
        GridWind2_IMU(pGS, &hImg, putFile.GetPathName(), &x0, &x1, &y0, &y1,
&z0, &z1, _l(IMU_WIND_DUMMY));
        //if (iCheckError_SYS(pGS)) goto GEO_EXIT;
        
        Destroy_IMG(pGS,&hImg);
    }
    goto DONE;
GEO_EXIT:
    AfxMessageBox("Some error ocurred!");
    if (pGS) 
    {
        ShowError_GEO(pGS);  // does nothing if there are no errors
    }
DONE:
    _fcloseall();
    return(0);
}

> Thanks,
> Jacques Beaurain
> AATS
> Room 908
> Tel: +27 11 6383007
> Cel: 082 322 7530
> 
_______________________________________________________
More mailing list info http://www.geosoft.com/support/listserv/index.html

Reply via email to