How to write to a file in Go - file-io

I have seen How to read/write from/to file using golang? and http://golang.org/pkg/os/#File.Write but could not get answer.
Is there a way, I can directly write an array of float/int to a file. Or do I have to change it to byte/string to write it. Thanks.

You can use the functions in the encoding/binary package for this purpose.
As far as writing an entire array at once goes, there are no functions for this. You will have to iterate the array and write each element individually. Ideally, you should prefix these elements with a single integer, denoting the length of the array.
If you want a higher level solution, you can try the encoding/gob package:
Package gob manages streams of gobs - binary values exchanged between an Encoder (transmitter) and a Decoder (receiver). A typical use is transporting arguments and results of remote procedure calls (RPCs) such as those provided by package "rpc".

Related

Best way to use edge_is_constrained_map with make_mesh_3?

I would like to pass on an edge_is_constrained_map obtained from the corefine_and_compute_intersection to make_mesh_3 so that the edges are preserved during meshing. I have tried to find the best way to do this but have not found anything on the subject. The only mechanism to pass on protected features manually to make_mesh_3 I could find is trough polylines, but I sort of expect there to also be a mechanism to pass on constrained maps as is the case for tetrahedral_isotropic_remeshing. Is there otherwise a function to convert an edge_is_constrained_map containing multiple line segments into valid polylines? Or is there another way of passing an edge_is_constrained_map to make_mesh_3?

Run-State values within shape script EA

Enterprise Architect 13.5.
I made MDG technology extending Object metatype. I have a shape script for my stereotype working well. I need to print several predefined run-state parameters for element. Is it possible to access to run-state params within Shape ?
As Geert already commented there is no direct way to get the runstate variables from an object. You might send a feature request to Sparx. But I'm pretty sure you can't hold your breath long enough to see it in time (if at all).
So if you really need the runstate in the script the only way is to use an add-in. It's actually not too difficult to create one and Geert has a nice intro how to create it in 10 minutes. In your shape script you can print a string restult returned from an operation like
print("#addin:myAddIn,pFunc1#")
where myAddIn is the name of the registered operation and pFunc1 is a parameter you pass to it. In order to control the script flow you can use
hasproperty('addin:myAddIn,pFunc2','1')
which evaluates the returned string to match or not match the string 1.
I once got that to work with no too much hassle. But until now I never had the real need to use it somewhere in production. Know that the addin is called from the interpreted script for each shaped element on the diagram and might (dramatically) affect rendering times.

reverse function: from output to input

there is a simple function that from a configuration file, with its value, return a byte array and then the following functions write it on Data Memory on a PLC.
Here is my question: i need to read firt of all these data Memory, get its values, and check if is there any different value with my configuration file's values.
Then from this byte array, write the corrispondentig values on the configuration file; in other word i need a reverse function that from output returns the input.
I think it is a very usefull function.
Maybe using reflection??
Thanks for any help
Matteo M.

Splitting Nef polyhedra into discrete volumes for conversion to regular polyhedra

I am doing some boolean operation on Nef polyhedra converted from regular polyhedra. After doing the boolean operation I want to convert the resulting Nef polyhedra into regular polyhedra. However it seems that Nef polyhedra only support if the result is a single volume. Some boolean operations however result in multiple volumes. Is there a way to split the Nef polyhedron into into the discrete volumes it contains and convert these back to regular polyhedra separately? Alternatively is there some more appropriate approach?
I have found the Nef_polyhedron_3::Volume and the corresponding iterator, but i have not been able to identify a way to utilize these to split up the Nef Polyhedron.
Edit:
I finally got around to properly look at this. The code provided worked almost out of the box. I ran in to a few issues that were pretty easily solved. First, i implemented BuildPolyhedronFromShell outside the Nef_polyhedron class as i would like to keep my CGAl Implementation as clean as possible. It was however necessary to make Nef_polyhedron_3::Triangulation_handler2 public, as it is used in BuildPolyhedronFromShell.
Additionally the code initially create shells with inward facing normals. This was fixed by changing Halffacet_const_handle f = opposite_facet->twin(); to Halffacet_const_handle f = opposite_facet; I don't know if this solves the problem in the general case, but i works for the cases i tried.
Thank you for the help.

SBJSON append new data into existing JSON file without parsing it first

I am making an app that lets the user draw on the screen in different colors and brush sizes. I am storing the info about each drawn path in a JSON file once it has been drawn to keep it out of memory. Right now I have it parsing all existing paths, then adding the new one in and writing it all back out again. I want it to simply append the new data into the JSON file without having to read it in and parse it first, that will make it so only one path is ever in memory at a time.
I am using SBJSON, the JSONWriter has a few append functions but I think you need to have the JSON string to append it to first, not the file, meaning I would have to read in the file anyway. Is there a way to do this without reading in the file at all? I know exactly how the data is structured.
It's possible, but you have to cheat a little. You can just create a stand-alone JSON document per path, and append that to the file. So you'll have something like this in your file:
{"name":"path1", "from": [0,3], "to":[3, 9]}
{"name":"path2", "from": [0,3], "to":[3, 9]}
{"name":"path3", "from": [0,3], "to":[3, 9]}
Note that this is not ONE JSON document but THREE. Handily, however, SBJsonStreamParser supports reading multiple JSON documents in one go. Set the supportMultipleDocuments property and plug it into a SBJsonStreamParserAdapter, and off you go. This also has the benefit that if you have many, many paths in your file as you can start drawing before you're finished reading the whole file. (Because you get a callback for each path.)
You can see some information on the use case here.
I'm pretty sure its not possible...what I ended up doing was reading in the JSON file as a string then instead of wasting memory changing all that into Dictionaries and Arrays, I just looked for an instance of part of the string (ex: i wanted to insert something before the string "], "texts"" showed up) where I wanted to insert data and inserted it there and wrote it back out to file.
As far as I can tell this is the best solution.