Index: codes/icosagcm/devel/Python/test/py/test_xios.py
===================================================================
--- codes/icosagcm/devel/Python/test/py/test_xios.py	(revision 692)
+++ codes/icosagcm/devel/Python/test/py/test_xios.py	(revision 694)
@@ -1,8 +1,5 @@
-#print 'import dynamico'
-#import dynamico
 import dynamico.unstructured as unst
 import dynamico.xios as xios
-#from dynamico.meshes import MPAS_Format, Unstructured_Mesh, radian
-from dynamico.meshes import radian, MPAS_Format, Unstructured_Mesh, Unstructured_PMesh as PMesh, Local_Mesh as Mesh
+from dynamico.meshes import radian, MPAS_Format, Unstructured_PMesh as PMesh, Local_Mesh as Mesh
 
 from mpi4py import MPI
@@ -14,18 +11,4 @@
 import cProfile
 import re
-
-def boundaries(degree,points,lon,lat):
-    n, nvertex = len(degree), degree.max()
-    bnd_lon, bnd_lat = np.zeros((n,nvertex)),np.zeros((n,nvertex))
-    for ij in range(n):
-        nb=degree[ij]
-        for k in range(nb):
-            vertex = points[ij,k]
-            bnd_lon[ij,k]=lon[vertex]
-            bnd_lat[ij,k]=lat[vertex]
-        for k in range(nb,nvertex):   # repeat last vertex if nb<nvertex
-            bnd_lon[ij,k]=bnd_lon[ij,nb-1]
-            bnd_lat[ij,k]=bnd_lat[ij,nb-1]
-    return bnd_lon, bnd_lat
 
 #----------------------------- read MPAS mesh --------------------------------
@@ -39,109 +22,30 @@
 print 'Reading MPAS mesh ...'
 meshfile = MPAS_Format('grids/x1.%d.grid.nc'%grid)
-#mesh = Unstructured_Mesh(meshfile, llm, nqdyn, radius, f)
 pmesh = PMesh(comm,meshfile)
 mesh = Mesh(pmesh, llm, nqdyn, radius, f)
-ni_glo = pmesh.dim_primal.n
-ni_loc = len(mesh.primal_own_glo)
 print '...Done'
 
-lon_i, lat_i, lon_v, lat_v = [x*radian for x in mesh.lon_i, mesh.lat_i, mesh.lon_v, mesh.lat_v]
+#--------------------------------- write some data ----------------------------------------
 
-#--------------------------------- initialize XIOS --------------------------
+context=xios.XIOS_Context(pmesh,mesh,nqtot)
 
-def setup_domain(cat,id, degree,vertex,lon,lat,lon_v,lat_v, ncell_glo=None, index_glo=None, displ=None): # cat in 'domain','domaingroup'
-    bnd_lon, bnd_lat = boundaries(degree, vertex, lon_v, lat_v)
-    ncell, nvertex = bnd_lon.shape
-    if ncell_glo is None :
-        ncell_glo = ncell
-        index_glo = np.arange(ncell, dtype=np.int32)
-        displ = 0
-    mesh = xios.Handle(cat,id)
-    mesh.set_attr(type='unstructured')
-    mesh.set_attr(ni_glo=ncell_glo, ni=ncell, ibegin=displ, i_index=index_glo)
-    mesh.set_attr(lonvalue_1d=lon, latvalue_1d=lat)
-    mesh.set_attr(nvertex=nvertex,bounds_lon_1d=bnd_lon, bounds_lat_1d=bnd_lat)
-
-unst.ker.dynamico_setup_xios()
-
-if True:
-    lev, levp1, nq = [xios.Handle('axis',name) for name in 'lev', 'levp1', 'nq']
-    lev.set_attr(n_glo=llm, value=np.arange(llm))
-    levp1.set_attr(n_glo=llm+1, value=np.arange(llm+1))
-    nq.set_attr(n_glo=nqtot, value=np.arange(nqtot))
-     # primal mesh
-    mesh_i=setup_domain('domaingroup','i', mesh.primal_own_deg, mesh.primal_vertex,
-                            lon_i[mesh.primal_own_loc], lat_i[mesh.primal_own_loc],
-                            lon_v, lat_v,
-                            pmesh.dim_primal.n, mesh.primal_own_glo, mesh.displ)
-#    mesh_i=setup_domain('domaingroup','i', mesh.primal_deg, mesh.primal_vertex-1, lon_i, lat_i, lon_v, lat_v) # primal mesh
-#    mesh_v=setup_domain('domain','v', mesh.dual_deg, mesh.dual_vertex-1, lon_v, lat_v, lon_i, lat_i) # dual mesh
-
-#   CALL xios_set_domain_attr("u",ni_glo=ncell_tot, ibegin=displ, ni=ncell)                                                                              
-#   CALL xios_set_domain_attr("u", data_dim=1, type='unstructured' , nvertex=2, i_index=ind_glo)                                                         
-#   CALL xios_set_domain_attr("u",lonvalue_1d=lon, latvalue_1d=lat, bounds_lon_1d=bounds_lon, bounds_lat_1d=bounds_lat)                                   
-#mesh_e = xios.Handle('domain','u')
-
-# works up to that point !
-
-dtime = xios.Duration(second=3600.)
-
-#   CALL xios_set_timestep(dtime)                                                                                                                        
-if True:
-    calendar=xios.Handle('calendar_wrapper')
-    print (dtime.year, dtime.month, dtime.day, dtime.hour, dtime.second)
-    calendar.set_attr(timestep=dtime)
-    calendar.update_timestep()
-else:
-    unst.ker.dynamico_xios_set_timestep(3600.)
-
-#   CALL xios_set_fieldgroup_attr("standard_output", freq_op=itau_out*xios_timestep, freq_offset=(itau_out-1)*xios_timestep)                             
-if False:
-    std=xios.Handle('fieldgroup','standard_output')
-    std.set_attr(freq_op=dtime)
-    freq_offset = xios.Duration(second=0)
-    std.set_attr(freq_offset=freq_offset)
-
-if True:
-    print 'xios.context_close_definition()'
-    xios.context_close_definition()
-
+lat_i = radian*mesh.lat_i
 lat_ik, junk  = np.meshgrid(lat_i, np.arange(llm), indexing='xy')
 
-def send_field1_primal(name, data):
-#    print 'send_field1_primal :', data.shape
-    data = data[mesh.primal_own_loc]
-    data = np.ascontiguousarray(data)
-    print 'send_field1_primal :', data.shape
-    xios.send_field(name, data)
-def send_field2_primal(name, data):
-#    print 'send_field2_primal :', data.shape
-    data = data[:,mesh.primal_own_loc]
-    data = np.ascontiguousarray(data)
-    print 'send_field2_primal :', data.shape
-    xios.send_field(name, data)
-    
 no_error=True
 try:
     for i in range(100):
-        if True:
-            unst.ker.dynamico_xios_update_calendar(i)
-        else:
-            xios.update_calendar(i)
+        context.update_calendar(i)
         print 'send_field', i
-        send_field1_primal('ps', lat_i)
-        send_field2_primal('theta', lat_ik)
+        context.send_field_primal('ps', lat_i)
+        context.send_field_primal('theta', lat_ik)
 except:
     print 'An error has occured, trying to close XIOS properly'
     no_error=False
-# CALL xios_recv_field(name,field)                                                                                                                       
-# CALL xios_send_field(name,field_tmp)                                                                                                                   
 
 print 'xios.context_finalize()'
-xios.context_finalize()
-
+context.finalize()
 print 'xios.finalize()'
 xios.finalize()
-
 print 'Done'
 
