CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   CFX (http://www.cfd-online.com/Forums/cfx/)
-   -   Importing XYZ data from .csv file. (http://www.cfd-online.com/Forums/cfx/82890-importing-xyz-data-csv-file.html)

mtledmund December 8, 2010 12:21

Importing XYZ data from .csv file.
 
Hello everyone,

I have a .csv file in the following format:
400,5000,600
500,6000,400
400,5000,990

All the variables are separated with a comma.

I want to open the csv file with perl and then create points with all the x y z from that file. So far, I have done the following:

! $data_file = "myfile.csv"; # Defining the data file name.
! open my $HANDLE, $data_file; # Opening the data file
#! @pts_data = (<HANDLE>); # Storing all the data in an array "pts_data"

! foreach (<my $HANDLE>)
! {

! my @file_line = split(/\t/,$_);
! $x_coor = $file_line[0];
! $y_coor = $file_line[1];
! $z_coor = $file_line[2];

#! ($x_coor, $y_coor, $z_coor) = split (/\,/,$_); # Set coordinates from file, xyz splitted by a comma (,).

# Then I create the point, I skipped the section for the post.

!}
!close ($HANDLE)
Can someone please tell me what's wrong with it? Thanks.
Edmund

AliTr December 9, 2010 21:17

1 Attachment(s)
#Check this one


! open(NAMES,"C:/Java/Points.csv") || die "Can't open file $!\n";

! $PointNum=-1;

! while(<NAMES>){
! ( $Xp, $Yp, $Zp )= split(',', $_, 3);
! $PointNum++;
! Create_Point();
! }

! close NAMES;


! sub Create_Point{


! $PointName = "P " . $PointNum;


POINT: $PointName
Apply Instancing Transform = On
Colour = 1, 0, 0
Colour Map = Default Colour Map
Colour Mode = Constant
Colour Scale = Linear
Colour Variable = Pressure
Colour Variable Boundary Values = Hybrid
Culling Mode = No Culling
Domain List = /DOMAIN GROUP:All Domains
Draw Faces = On
Draw Lines = Off
Instancing Transform = /DEFAULT INSTANCE TRANSFORM:Default Transform
Lighting = On
Line Width = 2
Max = 0.0 [Pa]
Min = 0.0 [Pa]
Node Number = 1
Option = XYZ
Point = $Xp, $Yp, $Zp
Point Symbol = Ball
Range = Global
Specular Lighting = On
Surface Drawing = Smooth Shading
Symbol Size = 1
Transparency = 0.0
Variable = Pressure
Variable Boundary Values = Hybrid
Visibility = On
OBJECT VIEW TRANSFORM:
Apply Reflection = Off
Apply Rotation = Off
Apply Scale = Off
Apply Translation = Off
Principal Axis = Z
Reflection Plane Option = XY Plane
Rotation Angle = 0.0 [degree]
Rotation Axis From = 0 [m], 0 [m], 0 [m]
Rotation Axis To = 0 [m], 0 [m], 0 [m]
Rotation Axis Type = Principal Axis
Scale Vector = 1 , 1 , 1
Translation Vector = 0 [m], 0 [m], 0 [m]
X = 0.0 [m]
Y = 0.0 [m]
Z = 0.0 [m]
END
END

! } #end sub

mtledmund December 11, 2010 10:23

Quote:

Originally Posted by AliTr (Post 286810)
#Check this one


! open(NAMES,"C:/Java/Points.csv") || die "Can't open file $!\n";

! $PointNum=-1;

! while(<NAMES>){
! ( $Xp, $Yp, $Zp )= split(',', $_, 3);
! $PointNum++;
! Create_Point();
! }

! close NAMES;


! sub Create_Point{


! $PointName = "P " . $PointNum;


POINT: $PointName
Apply Instancing Transform = On
Colour = 1, 0, 0
Colour Map = Default Colour Map
Colour Mode = Constant
Colour Scale = Linear
Colour Variable = Pressure
Colour Variable Boundary Values = Hybrid
Culling Mode = No Culling
Domain List = /DOMAIN GROUP:All Domains
Draw Faces = On
Draw Lines = Off
Instancing Transform = /DEFAULT INSTANCE TRANSFORM:Default Transform
Lighting = On
Line Width = 2
Max = 0.0 [Pa]
Min = 0.0 [Pa]
Node Number = 1
Option = XYZ
Point = $Xp, $Yp, $Zp
Point Symbol = Ball
Range = Global
Specular Lighting = On
Surface Drawing = Smooth Shading
Symbol Size = 1
Transparency = 0.0
Variable = Pressure
Variable Boundary Values = Hybrid
Visibility = On
OBJECT VIEW TRANSFORM:
Apply Reflection = Off
Apply Rotation = Off
Apply Scale = Off
Apply Translation = Off
Principal Axis = Z
Reflection Plane Option = XY Plane
Rotation Angle = 0.0 [degree]
Rotation Axis From = 0 [m], 0 [m], 0 [m]
Rotation Axis To = 0 [m], 0 [m], 0 [m]
Rotation Axis Type = Principal Axis
Scale Vector = 1 , 1 , 1
Translation Vector = 0 [m], 0 [m], 0 [m]
X = 0.0 [m]
Y = 0.0 [m]
Z = 0.0 [m]
END
END

! } #end sub

Thank you so much AliTr, I just figured out that I must put the full path of the file. Thanks again! :)

Cheers,
mtledmund


All times are GMT -4. The time now is 20:44.