importctypes
iphreeqc=ctypes.CDLL("libiphreeqc.0.dylib",ctypes.RTLD_GLOBAL)# C structures from var.hclassVAR_TYPE(ctypes.Structure):_fields_=[("TT_EMPTY",ctypes.c_int),("TT_ERROR",ctypes.c_int),("TT_LONG",ctypes.c_int),("TT_DOUBLE",ctypes.c_int),("TT_STRING",ctypes.c_int)](TT_EMPTY,TT_ERROR,TT_LONG,TT_DOUBLE,TT_STRING)=map(ctypes.c_int,xrange(5))classVRESULT(ctypes.Structure):_fields_=[("VR_OK",ctypes.c_int),("VR_OUTOFMEMORY",ctypes.c_int),("VR_BADVARTYPE",ctypes.c_int),("VR_INVALIDARG",ctypes.c_int),("VR_INVALIDROW",ctypes.c_int),("VR_INVALIDCOL",ctypes.c_int)](VR_OK,VR_OUTOFMEMORY,VR_BADVARTYPE,VR_INVALIDARG,VR_INVALIDROW,VR_INVALIDCOL)=map(ctypes.c_int,xrange(0,-6,-1))class_U(ctypes.Union):_fields_=[("lVal",ctypes.c_long),("dVal",ctypes.c_double),("sVal",ctypes.c_char),("vresult",VRESULT)]classVAR(ctypes.Structure):_anonymous_=("pvar",)_fields_=[("pvar",_U),("type",VAR_TYPE)]# Run modelId=iphreeqc.CreateIPhreeqc()dbloade=iphreeqc.LoadDatabase(Id,"phreeqc.dat")estring=iphreeqc.OutputErrorString(Id)# Model inputiphreeqc.AccumulateLine(Id,"TITLE Example 2.--Temperature dependence of solubility")iphreeqc.AccumulateLine(Id," of gypsum and anhydrite ")iphreeqc.AccumulateLine(Id,"SOLUTION 1 Pure water ")iphreeqc.AccumulateLine(Id," pH 7.0 ")iphreeqc.AccumulateLine(Id," temp 25.0 ")iphreeqc.AccumulateLine(Id,"EQUILIBRIUM_PHASES 1 ")iphreeqc.AccumulateLine(Id," Gypsum 0.0 1.0 ")iphreeqc.AccumulateLine(Id," Anhydrite 0.0 1.0 ")iphreeqc.AccumulateLine(Id,"REACTION_TEMPERATURE 1 ")iphreeqc.AccumulateLine(Id," 25.0 75.0 in 50 steps ")iphreeqc.AccumulateLine(Id,"SELECTED_OUTPUT ")iphreeqc.AccumulateLine(Id," -file ex2.sel ")iphreeqc.AccumulateLine(Id," -user_punch true ")iphreeqc.AccumulateLine(Id," -reset false ")iphreeqc.AccumulateLine(Id," -simulation false ")iphreeqc.AccumulateLine(Id," -selected_out true ")iphreeqc.AccumulateLine(Id," USER_PUNCH ")iphreeqc.AccumulateLine(Id," -start ")iphreeqc.AccumulateLine(Id," 10 punch - LA('H+') ")iphreeqc.AccumulateLine(Id," -end ")iphreeqc.AccumulateLine(Id,"END ")# run modelrunout=iphreeqc.RunAccumulated(Id)estring2=iphreeqc.OutputErrorString(Id)a=iphreeqc.GetSelectedOutputRowCount(Id)b=iphreeqc.GetSelectedOutputColumnCount(Id)printaprintb# this works, gives correct number of rows and columnsvart=VAR()iphreeqc.VarInit(ctypes.byref(vart))c=iphreeqc.GetSelectedOutputValue(Id,43,0,ctypes.byref(vart))#tries to extract value from row 43, column 1printc# c is here VRESULT. this works properly giving the right error number (0 to -6). Gives 0 in this case which is VR_OK