The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Stream values to file
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

Dominik Paulkowski

Germany
Posts

Posted - 05/02/2007 :  09:04:16 AM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Origin Version (Select Help-->About Origin): 7.5G SR6
Operating System: Windows XP Prof

Hi there!

I want to stream values to a file. But there are some complications, I don't understand.

The file should be in one line like:
"Begin\r"+"C0\r"+dbl0+"\r"+"C1\r"+dbl1+"\r"+"C2\r"+dbl2+"\r"

My script looks like:

StringArray saFiletypes;
saFiletypes.SetSize( 2 );
saFiletypes[0]="[Data (*.dat)] *.dat";
saFiletypes[1]="[All (*.*)] *.*";

strFileName = "Filename.dat";
strFileNameAndPath = GetSaveAsBox( saFiletypes, strFilePath, strFileName, "Save As - Dialog" );

file ff(strFileNameAndPath, file::modeCreate | file::modeReadWrite);

char cBegin[7] = "Begin\r";
ff.Write(cBegin, sizeof(cBegin));

char cCoeff0[3] = "C0";
char cCoeff1[3] = "C1";
char cCoeff2[3] = "C2";
char cSeparator[2] = "\r";

ff.Write(cCoeff0, sizeof(cCoeff0));
ff.Write(cSeparator, sizeof(cSeparator));
ff.Write(&dblTmpKoeffC0, sizeof(dblTmpKoeffC0));
ff.Write(cSeparator, sizeof(cSeparator));
ff.Write(cCoeff1, sizeof(cCoeff1));
ff.Write(cSeparator, sizeof(cSeparator));
ff.Write(&dblTmpKoeffC1, sizeof(dblTmpKoeffC1));
ff.Write(cSeparator, sizeof(cSeparator));
ff.Write(cCoeff2, sizeof(cCoeff2));
ff.Write(cSeparator, sizeof(cSeparator));
ff.Write(&dblTmpKoeffC2, sizeof(dblTmpKoeffC2));
ff.Write(cSeparator, sizeof(cSeparator));

ff.Close();

The script creates this result (opened with text-editor):
"Begin\r"+" C0 \r"+" JZ:@\r"+" C1 \r"+" 4Y@"+" C2 \r"+" v ? \r"

The "\r" are real returns in a line. But there are some undiserable whitespaces and the doubles are cryptic.

What's wrong?

I tried ff.Write(strValue, strValue.GetLength()), too. But it was unkonwn identifier in the compiler. And in a stream fputs( strCoeffC0, stream ) was wrong, because "fputs" unknown.

Ciao,
Dominik

-------------------
:-Dipl.-Phys. Dominik Paulkowski
Fraunhofer Institute for Surface Engineering and Thin Films (IST)
Braunschweig
Germany

Mike Buess

USA
3037 Posts

Posted - 05/02/2007 :  10:15:03 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Dominik,

Not sure what's going on but it's much easier to format the string and use stdioFile:WriteString to write to file. You say you want to stream to file which means to me output is added at EOF if file exists. If that's not correct remove the file::modeNoTruncate attribute in the stdioFile declaration.

StringArray saFiletypes;
saFiletypes.SetSize( 2 );
saFiletypes[0]="[Data (*.dat)] *.dat";
saFiletypes[1]="[All (*.*)] *.*";

string strFilePath,strFileName = "Filename.dat";
string strFileNameAndPath = GetSaveAsBox( saFiletypes, strFilePath, strFileName, "Save As - Dialog" );

double dbl0 = PI/2.0;
double dbl1 = PI;
double dbl2 = 2.0*PI;

stdioFile ff(strFileNameAndPath,
file::modeReadWrite |
file::modeCreate |
file::modeNoTruncate);

string str;
ff.SeekToEnd();
ff.WriteString("Begin");
ff.WriteString("C0");
str.Format("%f",dbl0);
ff.WriteString(str);
ff.WriteString("C1");
str.Format("%f",dbl1);
ff.WriteString(str);
ff.WriteString("C2");
str.Format("%f",dbl2);
ff.WriteString(str);

ff.Close();

Output from one run to FileName.dat is...

Begin
C0
1.570796
C1
3.141593
C2
6.283185

Mike Buess
Origin WebRing Member
Go to Top of Page

Dominik Paulkowski

Germany
Posts

Posted - 05/03/2007 :  03:29:37 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Thanks, Mike! It works well.


-------------------
:-Dipl.-Phys. Dominik Paulkowski
Fraunhofer Institute for Surface Engineering and Thin Films (IST)
Braunschweig
Germany
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000