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
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 Stream values to file

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
Dominik Paulkowski Posted - 05/02/2007 : 09:04:16 AM
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
2   L A T E S T    R E P L I E S    (Newest First)
Dominik Paulkowski Posted - 05/03/2007 : 03:29:37 AM
Thanks, Mike! It works well.


-------------------
:-Dipl.-Phys. Dominik Paulkowski
Fraunhofer Institute for Surface Engineering and Thin Films (IST)
Braunschweig
Germany
Mike Buess Posted - 05/02/2007 : 10:15:03 AM
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

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000