Question-and-Answer Resource for the Building Energy Modeling Community
Get started with the Help page
Ask Your Question
2

run oconv with standard input from process within C#

asked 2015-10-07 08:28:41 -0600

updated 2015-10-07 09:47:05 -0600

Hi guys, I startet programming my own radiance library in C# and ended up with the following problem: I create my sky, materials and object as strings. When I write this string into a file and then run oconv to create the the octree everything works fine. If I copy/paste the string to the windows cmd using the oconv options "-f -" also everything is fine. But when I start oconv as a process and pass the string to the StandardInput, the octree is generated without warnings but rtrace returns "fatal: truncated octree". Has anyone an idea where the problem might be? thanks, fabian

edit retag flag offensive close merge delete

Comments

@redinkinc can you share the generated octree. That might help to figure out the reason.

Mostapha Roudsari's avatar Mostapha Roudsari  ( 2015-10-08 11:53:46 -0600 )edit

@mostapha of course. what's the best way to share files here?

redinkinc's avatar redinkinc  ( 2015-10-09 02:07:59 -0600 )edit

3 Answers

Sort by ยป oldest newest most voted
2

answered 2015-10-07 17:27:05 -0600

Your error is likely caused by the octree ending without an EOF indicator. When rtrace loads the octree it gets to the end of the file and thinks the octree was truncated because it doesn't see an EOF indicator. I think your problem stems from how you're ending the the oconv process. Normally when oconv reaches the end of the input it closes the stream creating an EOF indicator. I'm guessing that your oconv process is waiting for another string on the standard input when the process is terminated, so no EOF is written.

I know little about EOF and know nothing about C#, so can't offer much help of how to fix this, but I think you either need to send an EOF to oconv to end the process or you need to add an EOF to the end of the octree file separately.

edit flag offensive delete link more

Comments

1

There isn't anything that oconv is looking for as EOF, it just knows when it gets one. Can you share the code you're using to start the oconv process and write to the standard input. It might be as simple as closing a stream properly or exiting the process.

Andyrew's avatar Andyrew  ( 2015-10-08 12:55:44 -0600 )edit

To think about EOF is a good start for sure, because most of the times the window of the oconv process is not closing itself (I'm not hiding it, yet), so it seems to wait for another input. I tried a lot with EOF but never got to the point where it runs. perhaps somebody can tell me what oconv wants for EOF? Thanks, Fabian

redinkinc's avatar redinkinc  ( 2015-10-09 01:46:20 -0600 )edit

Code:

public string Execute(string program, string command, string input ) {
var proc = new Process()
{
 StartInfo = new ProcessStartInfo(program, command)
 {
  RedirectStandardInput = true,
  RedirectStandardOutput = true,
  UseShellExecute = false
 }
};
proc.Start();
proc.StandardInput.WriteLine(input);
proc.StandardInput.WriteLine((char)26); //EOF
proc.StandardInput.Flush();
proc.StandardInput.Close();

var result = proc.StandardOutput.ReadToEnd();

proc.WaitForExit();
proc.Close();

return result;
redinkinc's avatar redinkinc  ( 2015-10-09 01:50:28 -0600 )edit

I also tried using Write() instead of WriteLine() with and without EOF. Even tried to use StreamWriter, but the result always stays the same. I'm using this program call also with rtrace and rcalc to input the evaluation points. There everything works fine...

redinkinc's avatar redinkinc  ( 2015-10-09 02:10:49 -0600 )edit

maybe try switching the order of so that the process exits then read the result?

proc.WaitForExit();
var result = proc.StandardOutput.ReadToEnd();
Andyrew's avatar Andyrew  ( 2015-10-09 12:56:16 -0600 )edit
0

answered 2015-10-09 14:35:30 -0600

Are you sure that you aren't getting an oconv error ? You can troubleshoot your code by redirecting the stdout of oconv to a file. Then try and run rpict from command line using the same file that you wrote to in your C# code to see if your octree did get created without errors.

I have gotten the "fatal: truncated octree" error in the past due to incorrectly arranging materials in my files.

See below:

The file

#x.rad ..correct file..
!gensky 12 31 10

void plastic white
0
0
5 0.7 0.7 0.7 0 0

!genblinds white blinds 1 2 4 4 20 | xform -rz 90 -rx -90

works fine...

image description

While the file below won't work

#x.rad

!gensky 12 31 10


!genblinds white blinds 1 2 4 4 20 | xform -rz 90 -rx -90

void plastic white
0
0
5 0.7 0.7 0.7 0 0

image description

edit flag offensive delete link more

Comments

Yes I'm sure. I'm also fetching any exeptions from StandardError. Also if I write my "input" to a file and use this in oconv via the console everything works.

redinkinc's avatar redinkinc  ( 2015-10-10 12:01:46 -0600 )edit

Just out of curiosity, what if in your workflow you take the input file and convert it back to standard input by "type"-ing it and then pipe that to oconv? Can you also write that piped STDOUT to a file, and compare it in a decent text editor alongside the output your function generates?

rpg777's avatar rpg777  ( 2015-10-12 10:23:08 -0600 )edit

"type"ing the input file to oconv results also in a longer .oct. It is even a little bit longer than the one created from the files as parameter. But it ends in the same results as the working octree from files, without the truncated octree warning.

redinkinc's avatar redinkinc  ( 2015-10-12 12:45:46 -0600 )edit

Python has a module to launch processes similar to what you are doing in C#. However, I found that its not always a good idea to implement piping with a wrapper. Sometimes it just makes sense to let Radiance and DOS-shell do their thing than transporting binary data (as in the case of Oconv) between different processes. You can write the commands to a .bat file and then launch the .bat file with your code in C#. You can always interrupt/intercept a .bat file by using the wait method to do any data processing in between.

Sarith's avatar Sarith  ( 2015-10-12 12:57:33 -0600 )edit

Mostapha, who commented above, has created a fairly sophisticated wrapper/add-on for Radiance within his Honeybee plugin. Although it is written in Python for the most part, you can get a fair idea of what it takes to make Radiance work within such an environment...if you haven't already, check out..http://www.grasshopper3d.com/group/ladybug

Sarith's avatar Sarith  ( 2015-10-12 12:59:54 -0600 )edit
0

answered 2019-09-21 11:03:56 -0600

can you please share how you overcame this? I've tried outputting STDOUT to temp file and using RVU on it. I get octree error. (while the same oconv through prompt creates a functioning file).

I noticed that default output is UTF-8 and that the file is 10% larger than the prompt one, so I output it to ANSI; and its similar in size to prompt one, but still RVU can not open the file.

next thing to try is to save the binary stream directly... but I thought about asking for advice here first.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Training Workshops

Careers

Question Tools

1 follower

Stats

Asked: 2015-10-07 08:28:41 -0600

Seen: 942 times

Last updated: Oct 09 '15