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

data storing with c++

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 25, 2001, 07:41
Default data storing with c++
  #1
yfyap
Guest
 
Posts: n/a
i am using borland c++ in my coding. this is rather a c++ related question than a cfd question. the simulated results are stored during the computation in arrays, say Ut[i][j][n]. my question is how these data are stored permenantly in other c++ generated files, such as a text file (as in fortran), so that i can still retrieve these data whenever necessary without rerunning the computations again?

if these is not possible, (to command c++ to write the computed results into text file), how are these data being stored permanently?

besides, can the computed results be plotted directly after the computation, for example linking c++ to other software, or is there such function in c++ itself?

any advice is most welcome.
  Reply With Quote

Old   April 25, 2001, 11:12
Default Re: data storing with c++
  #2
Olivier Braun
Guest
 
Posts: n/a
Hello yfyap !

There are a lot of ways to store data persistently out of c++. You can write to files. As I am using vc++, I dont know about how borland organises the standard headers, but it might be near to something like

#include <stdio>

After that statement, you can use the "old C-Style write-functions. Use them as they are to write binary, with format strings (like "%8.3f" for a float with eight characters, 3 digit precision).

You can even use streams if you like to: #include <iostream>

Another nice possibility is to use database access classes for ODBC or DAO, you could put your data into a relational DB and even into an Excel Spreadsheet.

Via OLE you can "talk" to most software packages to have charts automaticalyy generated, but this depends on the software you like to use.

Best way is to have a look into a good book or into the borland online help (don' t know if it' s well described)

Good luck

Olivier
  Reply With Quote

Old   April 25, 2001, 15:46
Default Re: data storing with c++
  #3
Kang, Seok Koo
Guest
 
Posts: n/a
The easiest and most widely used method to creat file in C/C++ is using 'fopen' function. Since 'fopen' is a classical function of C, any famous C Compiler perceive it.

I believe you know basic C grammars.

First, you have to include header file which contains "fopen(...)".

Second, call 'fopen' which opens file. Usage : fopen(file name, type); You have to specify full path for file name.

Next, call 'fwrite(...)' or 'fprintf(...)' which writes data to file.

Finally, call 'fclose()' which closes stream.

The form of data is your choice. You can insert blank or carriage return. You may need a little practice to use FILE I/O function without difficulty.

You can know these by reading a intermediate C textbook.
  Reply With Quote

Old   April 26, 2001, 11:15
Default Re: data storing with c++
  #4
yfyap
Guest
 
Posts: n/a
thanks. regards, yfyap
  Reply With Quote

Old   April 26, 2001, 11:18
Default Re: data storing with c++
  #5
yfyap
Guest
 
Posts: n/a
thanks. by the way what is OLE? is it possible to send the data to microsoft excel, and of course have the data plotted there? thanks. regards, yfyap
  Reply With Quote

Old   April 26, 2001, 17:04
Default Re: data storing with c++
  #6
John C. Chien
Guest
 
Posts: n/a
(1). My suggestion is: read a book such as " teach yourself VC++" or something like that.
  Reply With Quote

Old   April 27, 2001, 08:22
Default file writing with c
  #7
vijay Pargaonkar
Guest
 
Posts: n/a
Dear this is how u should write it to file.

unsigned int i,j,n; FILE *fp = fopen("mydatafile.dat", "w"); /*NX is Maximum i index NY is maximum j index NZ is maximum n index Writing limits on indices to file */ fprintf(fp,"%d\t%d\t%d\n",NX,NY,NZ); for (i=0; i < Nx; i++) { for (j=0; j<NY; j++)

{

for(n=0;; n< NZ; n++)

{

fprintf(fp,"%lf",U[i][j][n]);

}

}

fprintf(fp,"\n");/*writes a blank line*/ } /* Dump what u want to dump into file using fprintf*/ fclose(fp); /* File closed */

This will create a file named mydatafile.dat in your working directory.

With warm regards Pargaonkar Vijay
  Reply With Quote

Old   April 27, 2001, 10:43
Default Re: data storing with c++
  #8
vijay pargaonkar
Guest
 
Posts: n/a
Dear here is the way you can do it.unsigned int i,j,n; FILE *fp = fopen("mydatafile.dat", "w"); //NX is Maximum i index //NY is maximum j index //NZ is maximum n index fprintf(fp,"%d\t%d\t%d\n",NX,NY,NZ); //Writing limits on indices to file for (i=0; i < Nx; i++) { for (j=0; j<NY; j++)

{

for(n=0;; n< NZ; n++)

{

fprintf(fp,"%lf",U[i][j][n]);

}//N

}//J

fprintf(fp,"\n"); //writes a blank line

}//I // Dump whatever u want to dump into the file using fprintf fclose(fp); // File closed for writing

With warm regards Pargaonkar Vijay C.

  Reply With Quote

Reply


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 Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Storing previous time step data mohanamuraly OpenFOAM Post-Processing 3 October 8, 2012 07:00
Problem in running ICEM grid in Openfoam Tarak OpenFOAM 6 September 9, 2011 17:51
CGNS vs Tecplot Data Format LWhitson2 Main CFD Forum 3 July 1, 2011 13:50
Storing data in unsteady simulations ems STAR-CCM+ 3 April 3, 2010 06:55
How to update polyPatchbs localPoints liu OpenFOAM Running, Solving & CFD 6 December 30, 2005 17:27


All times are GMT -4. The time now is 09:24.