|
[Sponsors] |
April 25, 2001, 08:41 |
data storing with c++
|
#1 |
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. |
|
April 25, 2001, 12:12 |
Re: data storing with c++
|
#2 |
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 |
|
April 25, 2001, 16:46 |
Re: data storing with c++
|
#3 |
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. |
|
April 26, 2001, 12:15 |
Re: data storing with c++
|
#4 |
Guest
Posts: n/a
|
thanks. regards, yfyap
|
|
April 26, 2001, 12:18 |
Re: data storing with c++
|
#5 |
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
|
|
April 26, 2001, 18:04 |
Re: data storing with c++
|
#6 |
Guest
Posts: n/a
|
(1). My suggestion is: read a book such as " teach yourself VC++" or something like that.
|
|
April 27, 2001, 09:22 |
file writing with c
|
#7 |
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 |
|
April 27, 2001, 11:43 |
Re: data storing with c++
|
#8 |
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. |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Storing previous time step data | mohanamuraly | OpenFOAM Post-Processing | 3 | October 8, 2012 08:00 |
Problem in running ICEM grid in Openfoam | Tarak | OpenFOAM | 6 | September 9, 2011 18:51 |
CGNS vs Tecplot Data Format | LWhitson2 | Main CFD Forum | 3 | July 1, 2011 14:50 |
Storing data in unsteady simulations | ems | STAR-CCM+ | 3 | April 3, 2010 07:55 |
How to update polyPatchbs localPoints | liu | OpenFOAM Running, Solving & CFD | 6 | December 30, 2005 18:27 |