CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > CFX

how to export every data w.r.t time to txt file

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree4Likes

Reply
 
LinkBack Thread Tools Display Modes
Old   April 6, 2014, 13:49
Default
  #81
Senior Member
 
Matthias Voß
Join Date: Mar 2009
Location: Berlin, Germany
Posts: 433
Rep Power: 11
mvoss is on a distinguished road
I am not sure but it seems illogical to me to name the output like a usual variable. Just name it FH and try again.
mvoss is offline   Reply With Quote

Old   April 6, 2014, 14:21
Default
  #82
New Member
 
Sagar
Join Date: Apr 2014
Posts: 10
Rep Power: 3
eaysk is on a distinguished road
Did you mean that I rename $vol_frac_fluid to $FH?

I did that but its still not working.
eaysk is offline   Reply With Quote

Old   April 6, 2014, 14:58
Default
  #83
New Member
 
Sagar
Join Date: Apr 2014
Posts: 10
Rep Power: 3
eaysk is on a distinguished road
Even the simplest of file writing commands don't seem to work for me.

I tried this-

COMMAND FILE:
CFX Post Version = 14.5.7
END

! open($FH, ">data.txt");

! printf($FH ,100);

! close($FH);

But it wrote nothing in data.txt
eaysk is offline   Reply With Quote

Old   April 6, 2014, 16:31
Default
  #84
Senior Member
 
Matthias Voß
Join Date: Mar 2009
Location: Berlin, Germany
Posts: 433
Rep Power: 11
mvoss is on a distinguished road
! open(FH, ">data.txt");

! printf(FH ,100);

! close(FH);
mvoss is offline   Reply With Quote

Old   April 6, 2014, 16:46
Default
  #85
New Member
 
Sagar
Join Date: Apr 2014
Posts: 10
Rep Power: 3
eaysk is on a distinguished road
I get an error now-

ERROR
CCL parser failed with message:
Perl Syntax errors detected:
No comma allowed after filehandle at (eval 5707) line 6.
eaysk is offline   Reply With Quote

Old   April 6, 2014, 17:12
Default
  #86
Senior Member
 
Matthias Voß
Join Date: Mar 2009
Location: Berlin, Germany
Posts: 433
Rep Power: 11
mvoss is on a distinguished road
! open (MYFILE, '>>data.txt');
! print MYFILE "Bob\n";
! close (MYFILE);
mvoss is offline   Reply With Quote

Old   April 7, 2014, 05:38
Default
  #87
New Member
 
Sagar
Join Date: Apr 2014
Posts: 10
Rep Power: 3
eaysk is on a distinguished road
That isn't working either.

Is it necessary to include any perl libraries into the code? What I mean is that in C, when printf is used, it becomes necessary to include the standard input-output library using #include<stdio.h>. When other input-output functions cin and cout are used, we write #include<iostream.h>...

I have also created a file called file.txt or data.txt in the folder where I saved my data files 'bcp4_3_v4_sr4_omg15-13-00200' to 'bcp4_3_v4_sr4_omg15-13-28000' and the state file for 'Plane 1' before I ran the code.

But nothing is written into the files! Not even for simple commands like-

! open (MYFILE, '>>data.txt');
! print MYFILE "Bob\n";
! close (MYFILE);

But I don't get any errors either..

Note that I am able to load my datafiles, I am just not able to write to file.
eaysk is offline   Reply With Quote

Old   April 7, 2014, 05:48
Default
  #88
Senior Member
 
Matthias Voß
Join Date: Mar 2009
Location: Berlin, Germany
Posts: 433
Rep Power: 11
mvoss is on a distinguished road
Try to do a search on the created file "data.txt" in your system. If there is no error, then the task was completed. And at least an empty data.txt was created somewhere.
mvoss is offline   Reply With Quote

Old   April 7, 2014, 06:18
Default
  #89
Senior Member
 
Lance
Join Date: Mar 2009
Posts: 512
Rep Power: 11
Lance is on a distinguished road
Check that the current directory is where you think it is.

Code:
!use Cwd;
!print cwd();
Lance is online now   Reply With Quote

Old   April 7, 2014, 06:37
Default
  #90
New Member
 
Sagar
Join Date: Apr 2014
Posts: 10
Rep Power: 3
eaysk is on a distinguished road
There is no empty text file created. I thought that there should already be an existing file in the working directory with the name of the file that would contain the output.. So I created a text file in the working directory and then run the code. But it makes no difference whatever method I do. I can load the files but not write to files.

Should I be using the Command Editor of CFD-Post to process my code? Because I don't understand where a print function would display the output.. So I can't print the current working directory anywhere.
eaysk is offline   Reply With Quote

Old   April 7, 2014, 07:09
Default
  #91
Senior Member
 
Lance
Join Date: Mar 2009
Posts: 512
Rep Power: 11
Lance is on a distinguished road
Yes, use the command editor. I run CFX under linux and get the output to the terminal window. But I think that if you start cfd-post in stand alone there's an output window (think DOS-style) as well?
Lance is online now   Reply With Quote

Old   April 7, 2014, 08:14
Default
  #92
Senior Member
 
Bruno
Join Date: Mar 2009
Location: Brazil
Posts: 236
Rep Power: 12
brunoc is on a distinguished road
If printing the average volfrac at a plane is all you want to do, why not just use the built in chart from Post?

Anyway, try using the complete file path to the file you want to write. That might make things easier:

Code:
! open(OUT, ">E:/TEMP/test.txt");
! print OUT "testing:\n";
! printf(OUT "%.8e\n", 1.23);
! close(OUT);
You might also want to (temporarily) rename your working dir to something easier, such as, say, 'C:\myrun\', at least until you find out why script isn't working.

Code:
COMMAND FILE:
  CFX Post Version = 14.5.7
END

! my $file="C:/file.txt";
! open(FH, ">$file");
!
! $start = 200;
! $finish = 28000;
! $basename = "C:/bcp4_3_v4_sr4_omg15_pw3/bcp4_3_v4_sr4_ omg15_pw3 (fi=0.9097)/Data files/bcp4_3_v4_sr4_omg15-13";
! for ($i=$start; $i <= $finish; $i=$i+100)
! {
!   if($i<1000) {
      > load filename=$basename-00$i.dat
!   }
!   elsif($i<10000) {
      > load filename=$basename-0$i.dat
!   }
!   else {
      > load filename=$basename-$i.dat
!   }
!
!   $vol_frac_fluid = areaAve("Water.Volume Fraction", "Plane 1");
!   printf(FH "1.8f\n", $vol_frac_fluid);
! }
! close(FH);
brunoc is offline   Reply With Quote

Old   April 7, 2014, 09:18
Default
  #93
New Member
 
Sagar
Join Date: Apr 2014
Posts: 10
Rep Power: 3
eaysk is on a distinguished road
Thank you so much Bruno!

There were was wrong syntax i.e. backlash instead of frontslash, in the file specification..

It works file now

The basename suggestion doesn't work because the string gets formatted whenever \b comes up in the file name

Is it possible to make a chart for water.volumefraction vs. timestep directly using Post tools?
eaysk is offline   Reply With Quote

Old   April 7, 2014, 09:58
Default
  #94
Senior Member
 
Bruno
Join Date: Mar 2009
Location: Brazil
Posts: 236
Rep Power: 12
brunoc is on a distinguished road
Use slashes (/), not backslashes (\). A slash won't cause you problems. I tested it here and it worked fine.

And yes, it's possible to generate what you want using a chart in Post. You just need to create an expression with what you want to plot. One of the tutorials from CFX covers that. Look for the ones that use a transient setup or take a look at the documentation for charts in CFD-Post.
brunoc is offline   Reply With Quote

Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
swak4foam building problem GGerber OpenFOAM Installation 54 April 24, 2015 16:02
Moving mesh Niklas Wikstrom (Wikstrom) OpenFOAM Running, Solving & CFD 122 June 15, 2014 06:20
OpenFOAM on MinGW crosscompiler hosted on Linux allenzhao OpenFOAM Installation 127 January 30, 2009 20:08
DxFoam reader update hjasak OpenFOAM Post-Processing 69 April 24, 2008 01:24
Could anybody help me see this error and give help liugx212 OpenFOAM Running, Solving & CFD 3 January 4, 2006 19:07


All times are GMT -4. The time now is 05:16.