Personal tools
You are here: Home / cm / Wiki / ex2ipelem.pl
Navigation
Log in


Forgot your password?
 

ex2ipelem.pl

This perl script converts exelem files into ipelem files.

Plain Text icon ex2ipelem.pl — Plain Text, 2 KB (2814 bytes)

File contents

#! /bin/perl
#
# ........................................................................

# Name: trilinearex2ipelem.pl

# Description: Reads a frontend .exelem file containing 8-noded elements and converts that file to the backend. Very simple e.g. does not handle versions.

# Updates:

# Usage: trilinearex2ipelem.pl exelemfile ipelemfile

# ........................................................................

use strict;

if (scalar @ARGV < 2)
  {
	 print "Usage $0 exelemfile ipelemfile\n";
	 die;
  }

my $filenameIn = $ARGV[0];
my $filenameOut = $ARGV[1];
my $data;
my $number_location;
my $element_number;
my $number_of_nodes;
my $number_of_elements;
my $collapsed_basis;
my $one;
my $two;
my $three;
my $four;
my $five;
my $six;
my $seven;
my $eight;

open (INPUT_FILE,"<$filenameIn") || (die "Could not open file $filenameIn"); 
open (OUTPUT_FILE, ">$filenameOut") || (die "Could not open output file $filenameOut");
$number_of_elements=0;

print OUTPUT_FILE <<END_HEADER;
 CMISS Version 1.21 ipelem File Version 2
 Heading:

END_HEADER
print OUTPUT_FILE " The number of elements is [1]: ";
$number_location = tell OUTPUT_FILE;
print OUTPUT_FILE "XXXXX\n\n";

while (defined($data = <INPUT_FILE>))
  {
	 if ($data =~ m/#Nodes=\s*(\d+)/)
		{
		  $number_of_nodes = $1;
		}
	 if (($data =~ m/Element:\s*([0-9]+).*/) && ($1 > 0))
		{
		  #Only want top level elements.

		  $element_number = $1;
		  #print "found element $1\n";
		  if ($number_of_nodes == 8)
			 {
				$number_of_elements++;
				print OUTPUT_FILE " Element number [1]:      $element_number\n";
				
				#Read until we get the nodes
				while ((defined ($data = <INPUT_FILE>)) && !($data =~ m/Nodes:/))
				  {
				  }
				#Read the node numbers
				if ((defined ($data = <INPUT_FILE>)) && 
				  ($data =~ m/\s*([0-9]*)\s*([0-9]*)\s*([0-9]*)\s*([0-9]*)\s*([0-9]*)\s*([0-9]*)\s*([0-9]*)\s*([0-9]*)/))
				  {
					 $collapsed_basis = 0;
					 $one = $1;
					 $two = $2;
					 $three = $3;
					 $four = $4;
					 $five = $5;
					 $six = $6;
					 $seven = $7;
					 $eight = $8;
						  print OUTPUT_FILE <<END_ELEMENT;
 The number of geometric Xj-coordinates is [3]: 3
 The basis function type for geometric variable 1 is [1]:  1
 The basis function type for geometric variable 2 is [1]:  1
 The basis function type for geometric variable 3 is [1]:  1
 Enter the 8 global numbers for basis 1:  $one   $two   $three   $four   $five   $six   $seven   $eight

END_ELEMENT
              }
				else
				  {
					 die "Node numbers not found for element $element_number";
				  }
			 }
		  else
			 {
				die "Fatal error: $number_of_nodes nodes for the top level element is not supported.\n";
			 }
		}
  }
close INPUT_FILE;

seek (OUTPUT_FILE, $number_location, 0);
printf (OUTPUT_FILE "%5d", $number_of_elements);
close OUTPUT_FILE;