273 """ Converts Tecplot file generates by Oomph into Vtk XML file.
280 input = open(inputFilename,
"r")
282 error(
"Failed to open input file for reading !")
284 sys.stdout.write(
"Parse input file for Tecplot zones........")
293 (zone, line) = TecplotZone.parse(input, line)
294 except TecplotParsingError, e:
300 ignoredlines+=line-linetmp-1-zone.nodesCount()
307 sys.stdout.write(
"* %d lines ignored\n" % ignoredlines)
314 output = open(outputFilename,
"w")
316 error(
"Failed to open output file for writing !")
319 error(
"The input file " + inputFilename +
"\n does not contain any Tecplot zone! Created an empty file... \n You may want to try converting this file to point \n data with -p2 option if dim == 2 or -p3 option if dim == 3")
328 if zone.dimension > dimension:
329 dimension=zone.dimension
332 error(
"1D is not supported. Use GnuPlot to display the data file.")
338 nodesCount += zone.nodesCount()
339 cellsCount += zone.cellsCount[0]
343 fieldsCount = len(zones[0].nodes[0].fields)
349 output = open(outputFilename,
"w")
351 error(
"Failed to open output file for writing !")
353 output.write(VtkXml.header)
354 output.write(VtkXml.unstructuredGridHeader)
355 output.write(VtkXml.pieceHeader % (nodesCount, cellsCount))
360 sys.stdout.write(
"Write nodal coordinates...................")
362 output.write(VtkXml.pointsHeader)
364 for node
in zone.nodes:
365 output.write(
"%e %e %e\n" %(node.coordinates[0], node.coordinates[1], node.coordinates[2]))
366 output.write(VtkXml.pointsFooter)
372 output.write(VtkXml.cellsHeader)
376 sys.stdout.write(
"Write cell connectivity...................")
378 output.write(VtkXml.connectivityHeader)
385 if zone.cellFormat[0] == 1:
387 if zoneCount == 1: maxNode=0
390 for element
in range (0, zone.cellsCount[0]):
391 conn=zone.connectivities[element]
392 for i
in range(0, len(conn)):
395 if zoneCount > 1: dum+=maxNode+1
397 output.write(
"%i " %(conn[i]))
402 for element
in range (0, zone.cellsCount[0]):
403 conn=zone.connectivities[element]
404 for i
in range(0, len(conn)):
410 if zone.cellFormat[0] == 2:
414 if zone.dimension[0] == 1:
415 indexes = [pos, pos+1]
416 output.write(
" ".join(map(str, indexes)) +
"\n")
419 if zone.dimension[0] == 2:
422 for j
in range(dimJ - 1):
423 for i
in range(dimI - 1):
427 indexes[2] = pos + 1 + dimI
428 indexes[3] = pos + dimI
429 output.write(
" ".join(map(str, indexes)) +
"\n")
437 if zone.dimension[0] == 3:
441 for k
in range(dimK - 1):
442 for j
in range(dimJ - 1):
443 for i
in range(dimI - 1):
447 indexes[2] = pos + 1 + dimI
448 indexes[3] = pos + dimI
450 backPos = pos + dimI * dimJ
452 indexes[5] = backPos + 1
453 indexes[6] = backPos + 1 + dimI
454 indexes[7] = backPos + dimI
455 output.write(
" ".join(map(str, indexes)) +
"\n")
465 output.write(VtkXml.connectivityFooter)
470 sys.stdout.write(
"Write cell offsets........................")
472 output.write(VtkXml.offsetsHeader)
475 for i
in range(1,zone.cellsCount[0]+1):
476 if zone.cellType[0] == 3:
478 if zone.cellType[0] == 5:
480 if zone.cellType[0] == 9:
482 if zone.cellType[0] == 10:
484 if zone.cellType[0] == 12:
486 output.write(
str(offset) +
"\n")
487 output.write(VtkXml.offsetsFooter)
492 sys.stdout.write(
"Write cell types..........................")
495 output.write(VtkXml.typesHeader)
497 cellType0 = zones[0].cellType[0]
500 if zone.cellType[0] == 3:
502 if zone.cellType[0] == 5:
504 if zone.cellType[0] == 9:
506 if zone.cellType[0] == 10:
508 if zone.cellType[0] == 12:
511 if warn == 0
and not zone.cellType[0] == cellType0:
513 output.write(zone.cellsCount[0] * (cellType +
"\n"))
515 output.write(VtkXml.typesFooter)
518 sys.stdout.write(
"Warning: Different types of elements \n")
519 output.write(VtkXml.cellsFooter)
524 output.write(VtkXml.pointDataHeader)
525 for fieldIndex
in range(fieldsCount):
526 sys.stdout.write(
"Write field %02d/%02d........................." % (fieldIndex + 1, fieldsCount))
528 output.write(VtkXml.fieldHeader % (fieldIndex + 1))
530 for node
in zone.nodes:
531 output.write(
"%e\n" % node.fields[fieldIndex])
534 output.write(VtkXml.fieldFooter)
536 output.write(VtkXml.pointDataFooter)
538 output.write(VtkXml.pieceFooter)
539 output.write(VtkXml.unstructuredGridFooter)
540 output.write(VtkXml.footer)
#define max(a, b)
Definition: datatypes.h:23
str
Definition: compute_granudrum_aor.py:141