It is possible to call Geosoft library functions from C programs, and Geosoft ships several examples of how to do this, see for instance the examples in:
oasismontaj\gxdev\c However, I noted an error today in the way that the handles for Geosoft objects are initialized and checked for destruction. For instance, in the chanadd example, there are 4 different objects initialized, allocated, and destroyed: >> Initialized... // --- Program variables --- long hDB = 0; // handles set to 0 to indicate they are uninitialized long hVV = 0; long hVM = 0; long hVA = 0; >> Allocated... hDB = Open_DB(pGeo,argv[1],"SUPER",""); GEO_ERROR; // --- do we need a VV or a VA? --- lVA = iGetColVA_DB(pGeo,&hDB,&hChan); // number of elements in a VA, 1 if its a VV GEO_ERROR; if (lVA == 1) { // --- Create VV to hold data array --- hVV = CreateExt_VV(pGeo,_l(GS_DOUBLE),_l(0)); GEO_ERROR; } else { // --- its a VA channel --- hVA = CreateExt_VA(pGeo,_l(GS_DOUBLE),_l(0),&lVA); GEO_ERROR; } // --- get a real VM to to hold the data in memory --- hVM = Create_VM(pGeo,_l(GS_REAL),_l(0)); GEO_ERROR; >>> And destroyed ... if (hDB) Destroy_DB(pGeo,&hDB); GEO_ERROR; if (hVM) Destroy_VM(pGeo,&hVM); GEO_ERROR; // --- be careful not to try to destroy a VV owned by a VA --- if (hVV && (lVA != 1)) Destroy_VV(pGeo,&hVV); GEO_ERROR; >>>>>>>>>>>>> Note that when cleaning up, each objects value is checked to see if it has been reset from its initial value before the corresponding Destroy_XXX function is called. The problem with the above is that the values returned for the objects are not memory locations (where "NULL" and "0" might seem to be reasonable), but indices into a table of resources, and the index start at 0! The solution is thus to initialize the object handles to a value less than 0, and to check against that value before destroying the object. The example thus changes to: long hDB = -1; // handles set to -1 to indicate they are uninitialized long hVV = -1; // allocated resources are numbered from 0. long hVM = -1; long hVA = -1; and if (hDB!=-1) Destroy_DB(pGeo,&hDB); GEO_ERROR; if (hVM!=-1) Destroy_VM(pGeo,&hVM); GEO_ERROR; // --- be careful not to try to destroy a VV owned by a VA --- if (hVV!=-1 && (lVA != 1)) Destroy_VV(pGeo,&hVV); GEO_ERROR; Note that when creating the object, always call the GEO_ERROR macro immediately after the Create_XXX call: hVM = Create_VM(pGeo,_l(GS_REAL),_l(0)); GEO_ERROR; do NOT do this: hVM = Create_VM(pGeo,_l(GS_REAL),_l(0)); if(hVM==-1) { ....something else } _______________ Geosoft Inc. Stephen Cheesman [EMAIL PROTECTED] (905) 315-8207 Software and services for effective earth science decision-making. Free Oasis montaj interface now available at http://www.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