CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   Main CFD Forum (http://www.cfd-online.com/Forums/main/)
-   -   data storing with c++ (http://www.cfd-online.com/Forums/main/3386-data-storing-c.html)

yfyap April 25, 2001 07:41

data storing with c++
 
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.

Olivier Braun April 25, 2001 11:12

Re: data storing with c++
 
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

Kang, Seok Koo April 25, 2001 15:46

Re: data storing with c++
 
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.

yfyap April 26, 2001 11:15

Re: data storing with c++
 
thanks. regards, yfyap

yfyap April 26, 2001 11:18

Re: data storing with c++
 
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

John C. Chien April 26, 2001 17:04

Re: data storing with c++
 
(1). My suggestion is: read a book such as " teach yourself VC++" or something like that.

vijay Pargaonkar April 27, 2001 08:22

file writing with c
 
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

vijay pargaonkar April 27, 2001 10:43

Re: data storing with c++
 
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.



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