This file is indexed.

/usr/lib/python3/dist-packages/Magics/Magics.py is in python3-magics++ 3.0.0-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
# (C) Copyright 2012-2016 ECMWF.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
# In applying this licence, ECMWF does not waive the privileges and immunities
# granted to it by virtue of its status as an intergovernmental organisation nor
# does it submit to any jurisdiction.
#

import ctypes
import ctypes.util
import sys

import numpy as np
from numpy.ctypeslib import ndpointer
from functools import partial

lib = ctypes.util.find_library("MagPlus")

if lib is None:
    lib = "/usr/lib/libMagPlus.so"
    if lib is None:
      lib = "/build/magics++-6M026c/magics++-3.0.0/debian/build-py3/lib/libMagPlus.so"

dll  = ctypes.CDLL(lib)
libc = ctypes.CDLL(ctypes.util.find_library("c"))


class FILE(ctypes.Structure):
    pass


FILE_p = ctypes.POINTER(FILE)

######################## String conversions ##########################

def _string_to_char(x):
    return x.encode()


def _char_to_string(x):
    return x.decode()


def _convert_strings(fn):

    convert = False

    for a in fn.argtypes:
        if a is c_char_p:
            convert = True

    if fn.restype is c_char_p:
        convert = True

    if not convert:
        return fn

    def wrapped(*args):

        new_args = []
        for a, t in zip(args, fn.argtypes):
            if t is c_char_p:
                a = string_to_char(a)
            new_args.append(a)

        r = fn(*new_args)
        if fn.restype is c_char_p:
            r = char_to_string(r)
        return r

    return wrapped

if sys.version_info[0] > 2:
    convert_strings = _convert_strings
    char_to_string = _char_to_string
    string_to_char = _string_to_char
else:
    convert_strings = lambda x: x
    char_to_string = lambda x: x
    string_to_char = lambda x: x





####################################################################
c_int = ctypes.c_int
c_int_p = ctypes.POINTER(c_int)

c_double = ctypes.c_double
c_double_p = ctypes.POINTER(c_double)

c_char = ctypes.c_char
c_char_p = ctypes.c_char_p

c_void_p = ctypes.c_void_p


####################################################################
def checked_error_in_last_paramater(fn):

    def wrapped(*args):
        err = c_int(0)
        err_p = ctypes.cast(ctypes.addressof(err), c_int_p)
        params = [a for a in args]
        params.append(err_p)

        result = fn(*params)
        if err.value:
            raise MagicsError(err)
        return result

    return wrapped


def checked_return_code(fn):

    def wrapped(*args):
        err = fn(*args)
        if err:
            raise MagicsError(err)

    return wrapped


####################################################################

def return_type(fn, ctype):

    def wrapped(*args):
        result = ctype()
        result_p = ctypes.cast(ctypes.addressof(result), ctypes.POINTER(ctype))
        params = [a for a in args]
        params.append(result_p)
        fn(*params)
        return result.value

    return wrapped

####################################################################

init = dll.mag_open
init.restype = None
init.argtypes = None

####################################################################


@checked_return_code
def finalize():
    return dll.mag_close()

####################################################################

coast = dll.mag_coast
coast.restype = None
coast.argtypes = None

####################################################################

grib = dll.mag_grib
grib.restype = None
grib.argtypes = None

####################################################################

cont = dll.mag_cont
cont.restype = None
cont.argtypes = None

####################################################################

legend = dll.mag_legend
legend.restype = None
legend.argtypes = None

####################################################################

odb = dll.mag_odb
odb.restype = None
odb.argtypes = None

####################################################################

obs = dll.mag_obs
obs.restype = None
obs.argtypes = None

####################################################################

raw = dll.mag_raw
raw.restype = None
raw.argtypes = None

####################################################################

netcdf = dll.mag_netcdf
netcdf.restype = None
netcdf.argtypes = None

####################################################################

image = dll.mag_image
image.restype = None
image.argtypes = None

####################################################################

plot = dll.mag_plot
plot.restype = None
plot.argtypes = None

####################################################################

text = dll.mag_text
text.restype = None
text.argtypes = None

####################################################################

wind = dll.mag_wind
wind.restype = None
wind.argtypes = None

####################################################################

line = dll.mag_line
line.restype = None
line.argtypes = None

####################################################################

symb = dll.mag_symb
symb.restype = None
symb.argtypes = None

####################################################################

boxplot = dll.mag_boxplot
boxplot.restype = None
boxplot.argtypes = None

####################################################################

taylor = dll.mag_taylor
taylor.restype = None
taylor.argtypes = None

####################################################################

tephi = dll.mag_tephi
tephi.restype = None
tephi.argtypes = None

####################################################################

graph = dll.mag_graph
graph.restype = None
graph.argtypes = None

####################################################################

axis = dll.mag_axis
axis.restype = None
axis.argtypes = None

####################################################################

geo = dll.mag_geo
geo.restype = None
geo.argtypes = None

####################################################################

mimport = dll.mag_import
mimport.restype = None
mimport.argtypes = None

####################################################################

info = dll.mag_info
info.restype = None
info.argtypes = None

####################################################################

minput = dll.mag_input
minput.restype = None
minput.argtypes = None

####################################################################

eps = dll.mag_eps
eps.restype = None
eps.argtypes = None

####################################################################
###
###  Please note: these two functions changed compared to the previous SWIG based Python interface
###
metgraph = dll.mag_metgraph
metgraph.restype = None
metgraph.argtypes = None

epsinput = dll.mag_epsinput
epsinput.restype = None
epsinput.argtypes = None

####################################################################
###
###  Please note: this function was called mmetbufr to the previous SWIG based Python interface
###
metbufr = dll.mag_metbufr
metbufr.restype = None
metbufr.argtypes = None

####################################################################

epsgraph = dll.mag_epsgraph
epsgraph.restype = None
epsgraph.argtypes = None

####################################################################

epscloud = dll.mag_epscloud
epscloud.restype = None
epscloud.argtypes = None

####################################################################

epslight = dll.mag_epslight
epslight.restype = None
epslight.argtypes = None

####################################################################

epsplumes = dll.mag_epsplumes
epsplumes.restype = None
epsplumes.argtypes = None

####################################################################

epswind = dll.mag_epswind
epswind.restype = None
epswind.argtypes = None

####################################################################

epswave = dll.mag_epswave
epswave.restype = None
epswave.argtypes = None

####################################################################

epsbar = dll.mag_epsbar
epsbar.restype = None
epsbar.argtypes = None

####################################################################

epsshading = dll.mag_epsshading
epsshading.restype = None
epsshading.argtypes = None

####################################################################

wrepjson = dll.mag_wrepjson
wrepjson.restype = None
wrepjson.argtypes = None

####################################################################

geojson = dll.mag_geojson
geojson.restype = None
geojson.argtypes = None

####################################################################

mapgen = dll.mag_mapgen
mapgen.restype = None
mapgen.argtypes = None

####################################################################

mtable = dll.mag_table
mtable.restype = None
mtable.argtypes = None

####################################################################

seti = dll.mag_seti
seti.restype = None
seti.argtypes = (c_char_p, c_int)
seti = convert_strings(seti)

####################################################################

def set1i(name,data):
#    array = np.empty((size,), dtype=np.float64)
#    array_p = array.ctypes.data_as(c_double_p)
#    _set1r(name, array_p, size)
    size = len(data)
    name = string_to_char(name)
    array_p = (ctypes.c_int * size)(*data)
    dll.mag_set1i(ctypes.c_char_p(name), array_p, size)
    return None

####################################################################

array_2d_int = ndpointer(dtype=np.int,ndim=2, flags='CONTIGUOUS')
set2i = dll.mag_set2i
set2i.restype = None
set2i.argtypes = (c_char_p, array_2d_int, c_int, c_int)
set2i = convert_strings(set2i)

####################################################################

setr = dll.mag_setr
setr.restype = None
setr.argtypes = (c_char_p, c_double)
setr = convert_strings(setr)

####################################################################

def set1r(name,data):
    size = len(data)
    name = string_to_char(name)
    array_p = (ctypes.c_double * size)(*data)
    dll.mag_set1r(ctypes.c_char_p(name), array_p, size)
    return None

####################################################################

array_2d_double = ndpointer(dtype=np.double,ndim=2, flags='CONTIGUOUS')
set2r = dll.mag_set2r
set2r.restype = None
set2r.argtypes = (c_char_p, array_2d_double, c_int, c_int)
set2r = convert_strings(set2r)

####################################################################

setc = dll.mag_setc
setc.restype = None
setc.argtypes = (c_char_p, c_char_p)
setc = convert_strings(setc)

####################################################################
def set1c(name,data):
    new_data=[]
    for s in data:
       new_data.append(string_to_char(s))
    name = string_to_char(name)
    data_p = (c_char_p * (len(new_data)))(*new_data)
    dll.mag_set1c(ctypes.c_char_p(name), data_p, len(new_data))

####################################################################

#enqi = dll.mag_enqi
#enqi.restype  = c_int
#enqi.argtypes = (c_char_p,)

####################################################################

#enqr = dll.mag_enqr
#enqr.restype = c_double
#enqr.argtypes = (c_char_p,)

####################################################################

#enqc = dll.mag_enqc
#enqc.restype = c_char_p
#enqc.argtypes = (c_char_p,)

####################################################################

new_page = dll.mag_new
new_page.restype = None
new_page.argtypes = (c_char_p,)
new_page = convert_strings(new_page)

####################################################################

reset = dll.mag_reset
reset.restype = None
reset.argtypes = (c_char_p,)
reset = convert_strings(reset)

####################################################################

class MagicsError(Exception):

    def __init__(self, err):
        super(MagicsError, self).__init__("Magics Error - No Plot Produced!!! (%s)" % err)

####################################################################


#if __name__ == "__main__":
#    print "..."