#!/usr/bin/perl
#
# Script to create a radial mesh from a single 1D file
# Cjestmir de Boer 2008
##
# radius.sci and values.dat must have the same amount of lines
##
### To create radius.dat:
### cut -f 3 -d " " preX_XX.txt >radius.dat
### To create values.cat:
### cut -f 5 -d " " preX_XX.txt >values.dat
### Set the global variables, the file with the radius distances and the values
### file
### The File xymesh.dat will be created or overwritten if it allready exists.
$exp = @ARGV[0];
chomp($exp);
if (-e $exp){
print "the file _$exp\_ will be used for the radius and the values\n";
open(EXP, $exp);
@exper = ;
foreach $exp (@exper){
@exp=split(" ",$exp);
$radius=@exp[0];
chomp $radius;
push(@radius,$radius);
$values=@exp[1];
chomp $values;
push(@value,$values);
}
}
else
{
print "No filename given, radius.dat and values.dat will be used.\n";
if (!-e 'radius.dat'){
print "Please give a filename or place radius.dat";
exit;
}
else{
$radius = 'radius.dat';
open(RADIUS, $radius);
@radius = ;
}
if (!-e 'values.dat'){
print "Please give a filename or place values.dat";
exit;
}
else{
$values = 'values.dat';
open(VALUES, $values);
@value = ;
}
}
if (-e 'xymesh.dat')
{
print "xymesh.dat will be overwritten, continue? [y,n,newfile]\n";
$a = ; # Get input
chop $a;
if (($a eq "y") or ($a eq "Y")){
print "\n xymesh.dat will be overwritten\n";
open(XYMESH, '>xymesh.dat');
}
elsif (($a eq "n") or ($a eq "N")){exit;}
else
{
chomp $a;
open(XYMESH, ">$a");
}
}
$PI=4*atan2(1,1);
$key = 0;
$sizevalue = @value;
$sizeradius = @radius;
if ($sizeradius != $sizevalue){
print "values and radius files are not of equal length\n";
exit;
}
foreach $rad (@radius)
{
chomp $rad;
for ($a=0;$a<=$PI/3+$PI/32;$a=$a+$PI/32)
## for full circle use $a=-$PI;$a<=$PI instead
{
$cos=cos($a);
if (($a <0.000001)&&($a>-0.000001)){$a=0;}
if (($cos < 0.000001) && ($cos > -0.000001)){$cos=0;}
$sin=sin($a);
if (($sin < 0.000001) && ($sin > -0.000001)){$sin=0;}
$value = @value[$key];
chomp($value);
$xpoint = $rad*$cos;
$ypoint = $rad*$sin;
print XYMESH "$xpoint $ypoint $value\n";
}
print XYMESH "\n";
$key++
}
close(RADIUS);
close(VALUES);
close(XYMESH);
print "\n The mesh with the values in the third column is generated\n";
Call the program by using:
#mesh.pl