📄 inp2xml
字号:
#!/usr/bin/perl# Convert an inp mesh file to an xml file that can be read by DOLFIN## Usage: inp2xml mesh.inp mesh.xml## Copyright (C) 2002 Anders Logg.# Licensed under the GNU LGPL Version 2.1.## First added: 2002-12-06# Last changed: 2002use Text::ParseWords;# Open filesopen(INFILE,"<$ARGV[0]");open(OUTFILE,">$ARGV[1]");# State$state = "header";# Variables$nodes = 0;# Parse filewhile ($line=<INFILE>) { # Remove leading and trailing space $line =~ s/^\s+//; $line =~ s/\s+$//; # Convert line into list of words @words = &shellwords($line); # Convert if ( "$state" eq "header" ) { $nodes = @words[0]; $cells = @words[1]; print ( OUTFILE "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ); print ( OUTFILE "\n" ); print ( OUTFILE "<dolfin xmlns:dolfin=\"http://www.phi.chalmers.se/dolfin/\">\n" ); print ( OUTFILE " <mesh>\n"); print ( OUTFILE " <nodes size=\"$nodes\">\n" ); $state = "nodes"; } elsif ( "$state" eq "nodes" ) { $number = @words[0] - 1; $x = @words[1]; $y = @words[2]; $z = @words[3]; print ( OUTFILE " <node name=\"$number\" x=\"$x\" y=\"$y\" z=\"$z\"/>\n" ); if ( $number == ( $nodes - 1 ) ){ print ( OUTFILE " </nodes>\n" ); print ( OUTFILE " <cells size=\"$cells\">\n" ); $state = "cells"; } } elsif ( "$state" eq "cells" ) { $number = @words[0] - 1; $dummy = @words[1]; $type = @words[2]; if ( "$type" eq "tet" ) { $n0 = @words[3] - 1; $n1 = @words[4] - 1; $n2 = @words[5] - 1; $n3 = @words[6] - 1; print ( OUTFILE " <tetrahedron name=\"$number\" n0=\"$n0\" n1=\"$n1\" n2=\"$n2\" n3=\"$n3\"/>\n" ); if ( $number == ($cells - 1) ){ print ( OUTFILE " </cells>\n"); print ( OUTFILE " </mesh>\n"); print ( OUTFILE "</dolfin>"); } } elsif ( "$type" eq "tri" ) { $n0 = @words[3] - 1; $n1 = @words[4] - 1; $n2 = @words[5] - 1; print ( OUTFILE " <triangle name=\"$number\" n0=\"$n0\" n1=\"$n1\" n2=\"$n2\"/>\n" ); if ( $number == ($cells - 1) ) { print ( OUTFILE " </cells>\n"); print ( OUTFILE " </mesh>\n"); print ( OUTFILE "</dolfin>"); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -