David:

A couple of points about the suggested code:

The SetReal_VV function is not an efficient method for setting the values in
a VV, especially when writing a grid. I would recommend the iSetData_VV
function to do a full row at once:

                double zbuff[BUFSIZE], *pz;     // allocate enough...
                for ( long ny=0, pz=zbuff; ny<nys; ny++, pz++) {
                        zval = getval(nx,ny);
                        if ( zval == null ) zval = -1.e32;
                        *pz = zval;
                }
                iSetData_VV(pGeo,_l(0), &nys, zbuff, _l(GS_DOUBLE)); 

There is a minor bug in your code; the VV is allocated to nxs values, but
this should by nys. (In practice, this doesn't matter, because the VV is
automatically re-allocated to the required length by the SetRealVV function
if it is not long enough).

Stephen Cheesman
Geosoft Inc.

-----Original Message-----
From: David Humphrey [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, April 18, 2001 3:29 PM
To: '[EMAIL PROTECTED]'
Subject: RE: [gxnet]: C++ to creating grd files?


Funny you should ask.  That's the same problem I'm working on (see my prior
post about a related problem).  I'm using the GX Developer entry points to
write grid files.  Here's the data declaration of a grid object that we use
extensively:

class _declspec(dllexport) BGI_Grid {
protected:
        long            nxs, nys;                               //  Number
of columns and rows in the grid
        double  xmin, ymin;                             //  Coordinates of
the lower left corner of the grid
        double  xinc, yinc;                             //  Increment
between the grid columns
        double  rotation;                               //  Not used at this
time...maybe later
        double  null;                                   //  Standard null
value used internally
        double  userNull;                               //  Null value that
the user wants to see
        double  *z;                                     //  Array of grid
values


Here's a method out of to do the writing

/*--------------------------------------------------------------------*/
void BGI_Grid::writeGeosoft ( void *pGeo, char *fileName) {             //
write a grid in native Geosoft binary format
/*--------------------------------------------------------------------*/
        GX_HANDLE hGrd =
CreateNewFile_IMG(pGeo,_l(GS_DOUBLE),_l(1),&nxs,&nys,fileName);
        SetInfo_IMG(pGeo,&hGrd,&xinc,&yinc,&xmin,&ymin,&rotation);

        GX_HANDLE hCol = CreateExt_VV(pGeo,_l(GS_DOUBLE),&nxs);
        for ( long nx=0; nx<nxs; nx++ ) {
                for ( long ny=0; ny<nys; ny++ ) {
                        double zval = getval(nx,ny);
                        if ( zval == null ) zval = -1.e32;
                        SetReal_VV(pGeo,&hCol,&ny,&zval);
                }
                WriteX_IMG(pGeo,&hGrd,&nx,_l(0),&nys,&hCol);
        }

        Destroy_VV(pGeo,&hCol);
        Destroy_IMG(pGeo,&hGrd);
}

Regards,
David L. Humphrey
Manager, Software Development
Bell Geospace, Inc

-----Original Message-----
From: Ellis, Robert RG [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, April 18, 2001 2:13 PM
To: [EMAIL PROTECTED]
Subject: [gxnet]: C++ to creating grd files?


Hi,

I'm writing a standalone C++ program and have a regular grid of data in an
array v[i][j].  I want to create a Geosoft .grd file directly from that
array. Is there a definition of the grd file structure, or public code that
will generate a grd file from an array?

Thanks in advance,
Regards,

Rob

Robert G Ellis

Minerals Discovery Group, BHP World Exploration Inc.
1111 West Georgia Street, Suite 1400
Vancouver, BC, Canada, V6E 4M3
Telephone: (direct) 604 632 1470  (reception) 604 632 1450 Fax: 604 683 4125
EMAIL: [EMAIL PROTECTED] 

_______________________________________________________
More mailing list info http://www.geosoft.com/support/listserv/index.html
List Archive http://www.mail-archive.com/gxnet@lists.geosoft.com
_______________________________________________________
More mailing list info http://www.geosoft.com/support/listserv/index.html
List Archive http://www.mail-archive.com/gxnet@lists.geosoft.com
_______________________________________________________
More mailing list info http://www.geosoft.com/support/listserv/index.html
List Archive http://www.mail-archive.com/gxnet@lists.geosoft.com

Reply via email to