roc-film 1.13.4__py3-none-any.whl → 1.14.0__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- roc/__init__.py +2 -1
- roc/film/__init__.py +2 -2
- roc/film/commands.py +372 -323
- roc/film/config/__init__.py +0 -1
- roc/film/constants.py +101 -65
- roc/film/descriptor.json +126 -95
- roc/film/exceptions.py +28 -27
- roc/film/tasks/__init__.py +16 -16
- roc/film/tasks/cat_solo_hk.py +86 -74
- roc/film/tasks/cdf_postpro.py +438 -309
- roc/film/tasks/check_dds.py +39 -45
- roc/film/tasks/db_to_anc_bia_sweep_table.py +381 -0
- roc/film/tasks/dds_to_l0.py +232 -180
- roc/film/tasks/export_solo_coord.py +147 -0
- roc/film/tasks/file_handler.py +91 -75
- roc/film/tasks/l0_to_hk.py +117 -103
- roc/film/tasks/l0_to_l1_bia_current.py +38 -30
- roc/film/tasks/l0_to_l1_bia_sweep.py +417 -329
- roc/film/tasks/l0_to_l1_sbm.py +250 -208
- roc/film/tasks/l0_to_l1_surv.py +185 -130
- roc/film/tasks/make_daily_tm.py +40 -37
- roc/film/tasks/merge_tcreport.py +77 -71
- roc/film/tasks/merge_tmraw.py +102 -89
- roc/film/tasks/parse_dds_xml.py +21 -20
- roc/film/tasks/set_l0_utc.py +51 -49
- roc/film/tests/cdf_compare.py +565 -0
- roc/film/tests/hdf5_compare.py +84 -62
- roc/film/tests/test_dds_to_l0.py +93 -51
- roc/film/tests/test_dds_to_tc.py +8 -11
- roc/film/tests/test_dds_to_tm.py +8 -10
- roc/film/tests/test_film.py +161 -116
- roc/film/tests/test_l0_to_hk.py +64 -36
- roc/film/tests/test_l0_to_l1_bia.py +10 -14
- roc/film/tests/test_l0_to_l1_sbm.py +14 -19
- roc/film/tests/test_l0_to_l1_surv.py +68 -41
- roc/film/tests/test_metadata.py +21 -20
- roc/film/tests/tests.py +743 -396
- roc/film/tools/__init__.py +5 -5
- roc/film/tools/dataset_tasks.py +34 -2
- roc/film/tools/file_helpers.py +390 -269
- roc/film/tools/l0.py +402 -324
- roc/film/tools/metadata.py +147 -127
- roc/film/tools/skeleton.py +12 -17
- roc/film/tools/tools.py +109 -92
- roc/film/tools/xlsx2skt.py +161 -139
- {roc_film-1.13.4.dist-info → roc_film-1.14.0.dist-info}/LICENSE +127 -125
- roc_film-1.14.0.dist-info/METADATA +60 -0
- roc_film-1.14.0.dist-info/RECORD +50 -0
- {roc_film-1.13.4.dist-info → roc_film-1.14.0.dist-info}/WHEEL +1 -1
- roc/film/tasks/l0_to_anc_bia_sweep_table.py +0 -348
- roc_film-1.13.4.dist-info/METADATA +0 -120
- roc_film-1.13.4.dist-info/RECORD +0 -48
roc/film/tools/xlsx2skt.py
CHANGED
@@ -18,7 +18,6 @@ from openpyxl import load_workbook
|
|
18
18
|
from collections import OrderedDict
|
19
19
|
|
20
20
|
|
21
|
-
|
22
21
|
# ________________ HEADER _________________________
|
23
22
|
|
24
23
|
# Mandatory
|
@@ -40,30 +39,43 @@ CURRENT_DATETIME = datetime.now()
|
|
40
39
|
ROW_LENGTH_MAX = 79
|
41
40
|
DEF_INDENT = " " * 16
|
42
41
|
|
43
|
-
SHEET_NAMES = [
|
44
|
-
|
42
|
+
SHEET_NAMES = [
|
43
|
+
"header",
|
44
|
+
"GLOBALattributes",
|
45
|
+
"zVariables",
|
46
|
+
"VARIABLEattributes",
|
47
|
+
"Options",
|
48
|
+
"NRV",
|
49
|
+
]
|
45
50
|
|
46
51
|
CDF_OPTION_NAMES = ["CDF_COMPRESSION", "CDF_CHECKSUM"]
|
47
|
-
VAR_OPTION_NAMES = ["VAR_COMPRESSION",
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
HEADER_BOARD +=
|
54
|
-
"------------ ------- ---- -----"
|
52
|
+
VAR_OPTION_NAMES = ["VAR_COMPRESSION", "VAR_SPARSERECORDS", "VAR_PADVALUE"]
|
53
|
+
|
54
|
+
HEADER_BOARD = (
|
55
|
+
"! Variables G.Attributes "
|
56
|
+
+ "V.Attributes Records Dims Sizes\n"
|
57
|
+
)
|
58
|
+
HEADER_BOARD += (
|
59
|
+
"! --------- ------------ " + "------------ ------- ---- -----"
|
60
|
+
)
|
55
61
|
HEADER_SPACE = DEF_INDENT
|
56
62
|
|
57
63
|
GLOBAL_BOARD = "! Attribute Entry Data\n"
|
58
64
|
GLOBAL_BOARD += "! Name Number Type Value\n"
|
59
65
|
GLOBAL_BOARD += "! --------- ------ ---- -----"
|
60
66
|
|
61
|
-
VARIABLE_BOAD =
|
62
|
-
"
|
63
|
-
|
64
|
-
|
65
|
-
VARIABLE_BOAD +=
|
66
|
-
"
|
67
|
+
VARIABLE_BOAD = (
|
68
|
+
"! Variable Data Number "
|
69
|
+
+ " Record Dimension\n"
|
70
|
+
)
|
71
|
+
VARIABLE_BOAD += (
|
72
|
+
"! Name Type Elements"
|
73
|
+
+ " Dims Sizes Variance Variances\n"
|
74
|
+
)
|
75
|
+
VARIABLE_BOAD += (
|
76
|
+
"! -------- ---- -------- "
|
77
|
+
+ " ---- ----- -------- ---------"
|
78
|
+
)
|
67
79
|
|
68
80
|
VATTRS_BOARD = " ! Attribute Data\n"
|
69
81
|
VATTRS_BOARD += " ! Name Type Value\n"
|
@@ -73,22 +85,19 @@ VATTRS_BOARD += " ! -------- ---- -----"
|
|
73
85
|
# ________________ Class Definition __________
|
74
86
|
# (If required, define here classes)
|
75
87
|
class Xlsx2Skt:
|
76
|
-
|
77
|
-
""" Class to transform a formatted Excel file into a CDF skeleton table"""
|
88
|
+
"""Class to transform a formatted Excel file into a CDF skeleton table"""
|
78
89
|
|
79
90
|
def __init__(self, **kwargs):
|
80
|
-
|
81
|
-
self.
|
82
|
-
self.
|
83
|
-
self.
|
84
|
-
self.
|
85
|
-
self.
|
86
|
-
self.auto_pad = kwargs.pop('Auto_pad')
|
91
|
+
self.xlsx = kwargs.pop("xlsx_file")
|
92
|
+
self.skt = kwargs.pop("skt_file")
|
93
|
+
self.overwrite = kwargs.pop("Overwrite")
|
94
|
+
self.verbose = kwargs.pop("Verbose")
|
95
|
+
self.ignore = kwargs.pop("Ignore_none")
|
96
|
+
self.auto_pad = kwargs.pop("Auto_pad")
|
87
97
|
|
88
98
|
self.cdf_items = {}
|
89
99
|
|
90
100
|
def parse_xlsx(self):
|
91
|
-
|
92
101
|
"""Parse the Excel 2007 format file"""
|
93
102
|
|
94
103
|
xlsx = self.xlsx
|
@@ -112,8 +121,7 @@ class Xlsx2Skt:
|
|
112
121
|
if self.verbose:
|
113
122
|
logger.info("Loading %s sheet..." % (shtn))
|
114
123
|
if shtn not in sheet_names:
|
115
|
-
sys.exit("ERROR: Missing %s sheet in the input Excel file!"
|
116
|
-
% (shtn))
|
124
|
+
sys.exit("ERROR: Missing %s sheet in the input Excel file!" % (shtn))
|
117
125
|
else:
|
118
126
|
wksht = wkbk[shtn]
|
119
127
|
|
@@ -131,15 +139,15 @@ class Xlsx2Skt:
|
|
131
139
|
|
132
140
|
sheets[shtn] = sheet_data
|
133
141
|
|
134
|
-
self.cdf_items["GLOBALattributes"] =
|
135
|
-
|
136
|
-
|
137
|
-
self.cdf_items["VARIABLEattributes"] =
|
138
|
-
|
139
|
-
|
140
|
-
self.cdf_items["zVariables"] =
|
141
|
-
|
142
|
-
|
142
|
+
self.cdf_items["GLOBALattributes"] = uniq(
|
143
|
+
sheets["GLOBALattributes"]["Attribute Name"], not_none=True
|
144
|
+
)
|
145
|
+
self.cdf_items["VARIABLEattributes"] = uniq(
|
146
|
+
sheets["VARIABLEattributes"]["Attribute Name"], not_none=True
|
147
|
+
)
|
148
|
+
self.cdf_items["zVariables"] = uniq(
|
149
|
+
sheets["zVariables"]["Variable Name"], not_none=True
|
150
|
+
)
|
143
151
|
if self.verbose:
|
144
152
|
self._display()
|
145
153
|
|
@@ -147,23 +155,15 @@ class Xlsx2Skt:
|
|
147
155
|
|
148
156
|
def _display(self):
|
149
157
|
logger.info(
|
150
|
-
"%i GLOBAL attributes returned" % (
|
151
|
-
len(self.cdf_items["GLOBALattributes"])
|
152
|
-
)
|
158
|
+
"%i GLOBAL attributes returned" % (len(self.cdf_items["GLOBALattributes"]))
|
153
159
|
)
|
154
160
|
logger.info(
|
155
|
-
"%i Variable attributes returned"
|
156
|
-
|
157
|
-
)
|
158
|
-
)
|
159
|
-
logger.info(
|
160
|
-
"%i zVariables returned" % (
|
161
|
-
len(self.cdf_items["zVariables"])
|
162
|
-
)
|
161
|
+
"%i Variable attributes returned"
|
162
|
+
% (len(self.cdf_items["VARIABLEattributes"]))
|
163
163
|
)
|
164
|
+
logger.info("%i zVariables returned" % (len(self.cdf_items["zVariables"])))
|
164
165
|
|
165
166
|
def build_skt(self, xlsx_sheets):
|
166
|
-
|
167
167
|
"""Build the CDF skeleton table content using the Excel data"""
|
168
168
|
|
169
169
|
if self.verbose:
|
@@ -172,40 +172,50 @@ class Xlsx2Skt:
|
|
172
172
|
skt_name = os.path.splitext(os.path.basename(self.skt))[0]
|
173
173
|
xlsx_name = os.path.basename(self.xlsx)
|
174
174
|
|
175
|
-
file_header =
|
176
|
-
file_header +=
|
177
|
-
CURRENT_DATETIME.strftime("%Y-%m-%d %H:%M:%S") + "\n"
|
178
|
-
|
179
|
-
|
175
|
+
file_header = '!Skeleton table for the "' + skt_name + '" CDF.\n'
|
176
|
+
file_header += (
|
177
|
+
"!Generated: " + CURRENT_DATETIME.strftime("%Y-%m-%d %H:%M:%S") + "\n"
|
178
|
+
)
|
179
|
+
file_header += "!Skeleton table created by xlsx2skt.py V" + __version__ + "\n"
|
180
180
|
file_header += "!Skeleton table created from " + xlsx_name + "\n"
|
181
181
|
|
182
|
-
skt_header = self.build_header(xlsx_sheets["header"],
|
183
|
-
xlsx_sheets["Options"])
|
182
|
+
skt_header = self.build_header(xlsx_sheets["header"], xlsx_sheets["Options"])
|
184
183
|
skt_global = self.build_global(xlsx_sheets["GLOBALattributes"])
|
185
184
|
skt_vattrs = self.build_vattributes()
|
186
|
-
skt_zvars = self.build_zvariables(
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
185
|
+
skt_zvars = self.build_zvariables(
|
186
|
+
xlsx_sheets["zVariables"],
|
187
|
+
xlsx_sheets["VARIABLEattributes"],
|
188
|
+
xlsx_sheets["Options"],
|
189
|
+
xlsx_sheets["NRV"],
|
190
|
+
ignore_none=self.ignore,
|
191
|
+
auto_pad=self.auto_pad,
|
192
|
+
)
|
192
193
|
|
193
|
-
skt_body = "\n".join(
|
194
|
-
|
195
|
-
|
194
|
+
skt_body = "\n".join(
|
195
|
+
[
|
196
|
+
file_header,
|
197
|
+
"",
|
198
|
+
skt_header,
|
199
|
+
"",
|
200
|
+
skt_global,
|
201
|
+
"",
|
202
|
+
skt_vattrs,
|
203
|
+
"",
|
204
|
+
skt_zvars,
|
205
|
+
"",
|
206
|
+
"#end",
|
207
|
+
]
|
208
|
+
)
|
196
209
|
|
197
210
|
return skt_body
|
198
211
|
|
199
212
|
def write_skt(self, skt_body):
|
200
|
-
|
201
213
|
"""Write the CDF skeleton table file"""
|
202
214
|
|
203
215
|
skt = self.skt
|
204
216
|
|
205
217
|
if os.path.splitext(skt)[1] != ".skt":
|
206
|
-
logger.warning(
|
207
|
-
".skt extension will be automatically appended to %s" % skt
|
208
|
-
)
|
218
|
+
logger.warning(".skt extension will be automatically appended to %s" % skt)
|
209
219
|
skt = skt + ".skt"
|
210
220
|
|
211
221
|
if not (self.overwrite) and (os.path.isfile(skt)):
|
@@ -225,7 +235,6 @@ class Xlsx2Skt:
|
|
225
235
|
return None
|
226
236
|
|
227
237
|
def run(self):
|
228
|
-
|
229
238
|
"""Run the complete xlsx to skt conversion process"""
|
230
239
|
|
231
240
|
xlsx_sheets = self.parse_xlsx()
|
@@ -239,7 +248,6 @@ class Xlsx2Skt:
|
|
239
248
|
return False
|
240
249
|
|
241
250
|
def build_header(self, header_sheet, options_sheet):
|
242
|
-
|
243
251
|
"""Build the CDF skeleton table header part"""
|
244
252
|
|
245
253
|
if self.verbose:
|
@@ -257,16 +265,20 @@ class Xlsx2Skt:
|
|
257
265
|
nvattr = len(self.cdf_items["VARIABLEattributes"])
|
258
266
|
nvar = len(self.cdf_items["zVariables"])
|
259
267
|
|
260
|
-
header_board_info = [
|
261
|
-
|
268
|
+
header_board_info = [
|
269
|
+
" 0/" + str(nvar),
|
270
|
+
str(nglobal),
|
271
|
+
str(nvattr),
|
272
|
+
"0/z",
|
273
|
+
"0",
|
274
|
+
]
|
262
275
|
header_board_info = " ".join(header_board_info)
|
263
276
|
header_body.append(header_board_info)
|
264
277
|
|
265
278
|
header_opt_info = "\n"
|
266
279
|
for opt in CDF_OPTION_NAMES:
|
267
280
|
if opt in options_sheet:
|
268
|
-
header_opt_info += "!" + opt + ": " + \
|
269
|
-
options_sheet[opt][0] + "\n"
|
281
|
+
header_opt_info += "!" + opt + ": " + options_sheet[opt][0] + "\n"
|
270
282
|
header_body.append(header_opt_info)
|
271
283
|
|
272
284
|
header_body = "\n".join(header_body)
|
@@ -277,7 +289,6 @@ class Xlsx2Skt:
|
|
277
289
|
return header_body
|
278
290
|
|
279
291
|
def build_global(self, global_sheet):
|
280
|
-
|
281
292
|
"""Build the CDF skeleton table GLOBALattributes part"""
|
282
293
|
|
283
294
|
if self.verbose:
|
@@ -295,7 +306,6 @@ class Xlsx2Skt:
|
|
295
306
|
nindent = DEF_INDENT
|
296
307
|
new_entry = ""
|
297
308
|
for i, attr in enumerate(global_sheet["Attribute Name"]):
|
298
|
-
|
299
309
|
if attr is None:
|
300
310
|
continue
|
301
311
|
|
@@ -317,17 +327,18 @@ class Xlsx2Skt:
|
|
317
327
|
|
318
328
|
new_entry += enum_i + ": " + dtype_i + " { "
|
319
329
|
|
320
|
-
value_i = truncate_str(
|
321
|
-
|
322
|
-
|
323
|
-
|
330
|
+
value_i = truncate_str(
|
331
|
+
value_i,
|
332
|
+
int(ROW_LENGTH_MAX / 3),
|
333
|
+
gap=(" " * (len(new_entry) + 12)),
|
334
|
+
min_length=6,
|
335
|
+
)
|
324
336
|
|
325
337
|
new_entry += quote(value_i) + " }"
|
326
338
|
|
327
339
|
if len(new_entry) > ROW_LENGTH_MAX and int(enum_i) == 1:
|
328
340
|
nindent = len(attr)
|
329
|
-
new_entry = insert_char(new_entry, "\n" + " " * nindent,
|
330
|
-
nindent + 4)
|
341
|
+
new_entry = insert_char(new_entry, "\n" + " " * nindent, nindent + 4)
|
331
342
|
elif int(enum_i) == 1:
|
332
343
|
nindent = len(attr) + 14
|
333
344
|
|
@@ -343,13 +354,10 @@ class Xlsx2Skt:
|
|
343
354
|
return global_body
|
344
355
|
|
345
356
|
def build_vattributes(self):
|
346
|
-
|
347
357
|
"""Build the list of variable attributes"""
|
348
358
|
|
349
359
|
if self.verbose:
|
350
|
-
logger.debug(
|
351
|
-
"Building skeleton table variable attributes section..."
|
352
|
-
)
|
360
|
+
logger.debug("Building skeleton table variable attributes section...")
|
353
361
|
|
354
362
|
vattrs_body = ["#VARIABLEattributes", ""]
|
355
363
|
|
@@ -363,11 +371,15 @@ class Xlsx2Skt:
|
|
363
371
|
|
364
372
|
return vattrs_body
|
365
373
|
|
366
|
-
def build_zvariables(
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
374
|
+
def build_zvariables(
|
375
|
+
self,
|
376
|
+
zvars_sheet,
|
377
|
+
vattrs_sheet,
|
378
|
+
options_sheet,
|
379
|
+
nrv_sheet,
|
380
|
+
ignore_none=False,
|
381
|
+
auto_pad=True,
|
382
|
+
):
|
371
383
|
"""Build the CDF skeleton table VARIABLEattributes
|
372
384
|
and zVariables parts"""
|
373
385
|
|
@@ -379,12 +391,9 @@ class Xlsx2Skt:
|
|
379
391
|
zvar_body.extend(["#zVariables", ""])
|
380
392
|
|
381
393
|
for i, zvar in enumerate(zvars_sheet["Variable Name"]):
|
382
|
-
|
383
394
|
if zvar is None:
|
384
395
|
if ignore_none:
|
385
|
-
logger.warning(
|
386
|
-
"Warning: current zVariable is NoneType, skipping!"
|
387
|
-
)
|
396
|
+
logger.warning("Warning: current zVariable is NoneType, skipping!")
|
388
397
|
continue
|
389
398
|
else:
|
390
399
|
sys.exit("ERROR: Current zVariable is NoneType!")
|
@@ -403,9 +412,20 @@ class Xlsx2Skt:
|
|
403
412
|
|
404
413
|
if self.verbose:
|
405
414
|
logger.debug(
|
406
|
-
" "
|
407
|
-
|
408
|
-
|
415
|
+
" "
|
416
|
+
+ quote(zvar)
|
417
|
+
+ " "
|
418
|
+
+ dtype_i
|
419
|
+
+ " "
|
420
|
+
+ nelem_i
|
421
|
+
+ " "
|
422
|
+
+ dims_i
|
423
|
+
+ " "
|
424
|
+
+ sizes_i
|
425
|
+
+ " "
|
426
|
+
+ recvar_i
|
427
|
+
+ " "
|
428
|
+
+ dimvars_i
|
409
429
|
)
|
410
430
|
|
411
431
|
if dtype_i == "None":
|
@@ -420,9 +440,22 @@ class Xlsx2Skt:
|
|
420
440
|
if dimvars_i == "None":
|
421
441
|
dimvars_i = ""
|
422
442
|
|
423
|
-
zvar_entry =
|
424
|
-
"
|
425
|
-
|
443
|
+
zvar_entry = (
|
444
|
+
" "
|
445
|
+
+ quote(zvar)
|
446
|
+
+ " "
|
447
|
+
+ dtype_i
|
448
|
+
+ " "
|
449
|
+
+ nelem_i
|
450
|
+
+ " "
|
451
|
+
+ dims_i
|
452
|
+
+ " "
|
453
|
+
+ sizes_i
|
454
|
+
+ " "
|
455
|
+
+ recvar_i
|
456
|
+
+ " "
|
457
|
+
+ dimvars_i
|
458
|
+
)
|
426
459
|
|
427
460
|
if len(zvar_entry) > ROW_LENGTH_MAX:
|
428
461
|
zvar_entry = insert_char(zvar_entry, "\n", len(zvar) + 2)
|
@@ -434,8 +467,7 @@ class Xlsx2Skt:
|
|
434
467
|
if opt in options_sheet:
|
435
468
|
if opt == "VAR_PADVALUE" and auto_pad:
|
436
469
|
options_sheet[opt][0] = assign_pad(dtype_i)
|
437
|
-
var_opt_info += "! " + opt + ": " + \
|
438
|
-
options_sheet[opt][0] + "\n"
|
470
|
+
var_opt_info += "! " + opt + ": " + options_sheet[opt][0] + "\n"
|
439
471
|
zvar_body.append(var_opt_info)
|
440
472
|
|
441
473
|
# Add variable attributes info
|
@@ -443,27 +475,28 @@ class Xlsx2Skt:
|
|
443
475
|
|
444
476
|
vattr_entry = ""
|
445
477
|
for j, vattr_var in enumerate(vattrs_sheet["Variable Name"]):
|
446
|
-
|
447
478
|
if vattr_var == zvar:
|
448
479
|
vattr_entry += "\n"
|
449
480
|
vattr_name = quote(str(vattrs_sheet["Attribute Name"][j]))
|
450
481
|
vattr_dtype = str(vattrs_sheet["Data Type"][j])
|
451
482
|
if vattr_dtype == "None":
|
452
|
-
sys.exit(
|
453
|
-
|
454
|
-
|
483
|
+
sys.exit(
|
484
|
+
"ERROR: Wrong Data Type for the "
|
485
|
+
+ "attribute %s " % (vattr_name)
|
486
|
+
+ "of the variable %s !" % (zvar)
|
487
|
+
)
|
455
488
|
|
456
489
|
vattr_value = str(vattrs_sheet["Value"][j])
|
457
490
|
|
458
|
-
vattr_entry_j =
|
459
|
-
+ vattr_dtype + " { "
|
491
|
+
vattr_entry_j = (
|
492
|
+
" " + vattr_name + " " + vattr_dtype + " { "
|
493
|
+
)
|
460
494
|
|
461
495
|
if vattr_dtype == "CDF_CHAR":
|
462
496
|
gap = " " * (2 * len(vattr_entry_j) - 1)
|
463
|
-
vattr_value = truncate_str(
|
464
|
-
|
465
|
-
|
466
|
-
min_length=6)
|
497
|
+
vattr_value = truncate_str(
|
498
|
+
vattr_value, int(ROW_LENGTH_MAX / 3), gap=gap, min_length=6
|
499
|
+
)
|
467
500
|
vattr_value = quote(vattr_value)
|
468
501
|
|
469
502
|
vattr_entry += vattr_entry_j + vattr_value + " }"
|
@@ -479,8 +512,7 @@ class Xlsx2Skt:
|
|
479
512
|
val_k = str(nrv_sheet["Value"][k])
|
480
513
|
if (idx_k == "") or (idx_k == "None"):
|
481
514
|
sys.exit("ERROR: Wrong NRV index for %s!" % nrv_k)
|
482
|
-
nrv_body += " [" + idx_k + "] = { " + \
|
483
|
-
quote(val_k) + " }\n"
|
515
|
+
nrv_body += " [" + idx_k + "] = { " + quote(val_k) + " }\n"
|
484
516
|
|
485
517
|
if len(nrv_body) == 0:
|
486
518
|
nrv_body = " ! RV values were not requested.\n"
|
@@ -495,7 +527,6 @@ class Xlsx2Skt:
|
|
495
527
|
|
496
528
|
# ________________ Global Functions __________
|
497
529
|
def uniq(seq, not_none=False):
|
498
|
-
|
499
530
|
"""Get list of unique elements from an input sequence of list type"""
|
500
531
|
|
501
532
|
seen = set()
|
@@ -507,24 +538,20 @@ def uniq(seq, not_none=False):
|
|
507
538
|
|
508
539
|
|
509
540
|
def quote(string, unquote=False):
|
510
|
-
|
511
541
|
"""Double quote a given string"""
|
512
542
|
|
513
543
|
if string is not None:
|
514
|
-
if string.startswith("
|
544
|
+
if string.startswith('"'):
|
515
545
|
string = string[1:]
|
516
|
-
if string.endswith("
|
546
|
+
if string.endswith('"'):
|
517
547
|
string = string[:-1]
|
518
548
|
if unquote:
|
519
549
|
return string
|
520
|
-
return "
|
550
|
+
return '"' + string + '"'
|
521
551
|
|
522
552
|
|
523
|
-
def truncate_str(string, max_length,
|
524
|
-
|
525
|
-
min_length=3):
|
526
|
-
|
527
|
-
""" truncate a too long CDF_CHAR value"""
|
553
|
+
def truncate_str(string, max_length, gap=DEF_INDENT, min_length=3):
|
554
|
+
"""truncate a too long CDF_CHAR value"""
|
528
555
|
|
529
556
|
nstr = len(string)
|
530
557
|
new_string = ""
|
@@ -534,20 +561,18 @@ def truncate_str(string, max_length,
|
|
534
561
|
break
|
535
562
|
new_string += val_c
|
536
563
|
if (i % max_length == 0) and (i != 0):
|
537
|
-
new_string += "
|
564
|
+
new_string += '" - \n' + gap + '"'
|
538
565
|
|
539
566
|
return new_string
|
540
567
|
|
541
568
|
|
542
569
|
def insert_char(string, char, pos):
|
543
|
-
|
544
|
-
""" Insert substring in a string """
|
570
|
+
"""Insert substring in a string"""
|
545
571
|
|
546
572
|
return string[:pos] + char + string[pos:]
|
547
573
|
|
548
574
|
|
549
575
|
def assign_pad(data_type):
|
550
|
-
|
551
576
|
"""
|
552
577
|
Automatically assigns VAR_PADVALUE
|
553
578
|
depending to the input data_type
|
@@ -563,24 +588,21 @@ def assign_pad(data_type):
|
|
563
588
|
elif ("FLOAT" in dtype) or ("REAL" in dtype):
|
564
589
|
return "0.0"
|
565
590
|
elif "CHAR" in dtype:
|
566
|
-
return "
|
591
|
+
return '" "'
|
567
592
|
else:
|
568
593
|
return "None"
|
569
594
|
|
570
595
|
|
571
|
-
def make_cdf(skt_file, cdf_file=None,
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
""" Make a CDF format file from a skeleton
|
576
|
-
table using the skeletoncdf program """
|
596
|
+
def make_cdf(skt_file, cdf_file=None, exe="skeletoncdf", overwrite=False):
|
597
|
+
"""Make a CDF format file from a skeleton
|
598
|
+
table using the skeletoncdf program"""
|
577
599
|
|
578
600
|
if not os.path.isfile(skt_file):
|
579
601
|
logger.error(skt_file + " does not exist!")
|
580
602
|
return False
|
581
603
|
|
582
604
|
if cdf_file is None:
|
583
|
-
cdf_file = os.path.basename(skt_file).replace(
|
605
|
+
cdf_file = os.path.basename(skt_file).replace(".skt", ".cdf")
|
584
606
|
cdf_dir = os.path.dirname(skt_file)
|
585
607
|
cdf_file = os.path.join(cdf_dir, cdf_file)
|
586
608
|
|