source: dynamico_lmdz/simple_physics/phyparam/python/plugins.pyx @ 4236

Last change on this file since 4236 was 4236, checked in by dubos, 5 years ago

simple_physics : some Python bindings

File size: 1.0 KB
Line 
1#---------------------------------- logging plugin -------------------------------#
2
3cdef to_str(ptrlen, char[] ptr, start=0):
4     return str(bytes([ ptr[i+start*ptrlen] for  i in range(ptrlen)]), encoding='utf8').rstrip()
5
6"""
7  SUBROUTINE default_flush_plugin(lev, taglen, tag, buflen, bufsize, buf)
8    INTEGER(c_int), INTENT(IN), VALUE :: lev, taglen, buflen, bufsize
9    CHARACTER(KIND=c_char), INTENT(IN) :: tag(taglen), buf(buflen, bufsize)
10"""
11
12cdef flush_plugin_wrap(int lev, int taglen, char[] tag, int buflen, int bufsize, char[] buf):
13    flush_plugin(to_str(taglen, tag), [to_str(buflen, buf, i) for i in range(bufsize) ] )
14
15def default_flush_plugin(tag, buf):
16    if tag != 'missing_plugin' :
17        n = len(buf)
18        for i,line in enumerate(buf):
19            print( '[%s %2.2d/%2.2d] %s'%(tag, i+1, n, line) )
20
21def set_flush(plugin):
22    flush_plugin = plugin
23
24#----------------------------- plug plugins in ----------------------------------#
25
26flush_plugin = default_flush_plugin
27
28phy.phyparam_set_plugins_logging(&flush_plugin_wrap)
Note: See TracBrowser for help on using the repository browser.