The whole task is to convert a CAD data file (of polygonal 3D-model) from one format into another. I had no problem making that in C++ for my work, then I decided to program the task in J just for learning it. Both input and output data files contain two blocks: points and polygons (3- and 4-angled). The input file first contains many data, unnecessary for the output file, so it should be skipped. Then there is a something like:
*NODE
 100005-232.27999877930-422.06298828125 22.000000000000       0       0
 100006-234.33399963379-381.77999877930 22.000000000000       0       0
 100008-269.00201416016-379.25601196289 22.000000000000       0       0
                         ......
                         ......
$
This is the points definition. 8 characters - point ID, then 16x3 - x, y and z coordinates, then 8x2 - should be skipped. So, I need to read a part of the file from *NODE till the following '$' character (there are many '$' both before and after that block of data, so I can not use just any '$' as a delimiter), then split the strings by 8-16-16-16 pattern (rows are delimited by CR or CRLF, but there are no delimiters in a row, we can only count the characters).
Then somewhere later in the file is a block like:
*ELEMENT_SHELL
$    eid     pid      n1      n2      n3      n4
      1     100  110095  110099  110103  110022
      2     100  110164  110162  110175  110176
      3     100  110175  110158  110157  110177
             ....
*END
These are the polygons. Each value takes 8 chars here. The first two should be skipped. The next four are references to the IDs of points, defined earlier. If all four are different, then it is a quadrangle, if the last two are identical - a triangle (that's what my original question was concerned about).

The output file format is like this:
POINTS 1206 float
-232.27999877930 -422.06298828125  22.000000000000
-234.33399963379 -381.77999877930  22.000000000000
-269.00201416016 -379.25601196289  22.000000000000
             ....
             ....
POLYGONS 1212 5916
4 104 108 112 31
4 173 171 184 185
4 184 167 166 186
3 719 494 508
3 714 717 715
3 676 492 491
The fields in a string are delimited by space, and no matter how many characters they contain. Here 1206 is the number of points, 1212 - the number of polygons, 5916 is the number all fields used to define the polygons (i.e., 5*number_of_4angles + 4*number_of_3angles). The points has no explicitly defined IDs, as in the input file, so in the output point IDs are always start with 0 and grows by 1. So, the IDs from the input file should be changed to define the polygons in the output (for this particular examples 100005 will become 0, 100006 - 1, 100008 - 2 etc.). And in the strings after POLYGONS... first comes number of vertices (3 or 4), and then these changed point ids.
So, I've written:
load 'files'
a =. 'b' fread inputfilename
node_start =. 1 + (s: a) (e.i.1:) (s: ' *NODE')
node_end =. (s:(node_start }. a)) (e.i.1:) (s: ' $')
n_d =: node_end {. node_start }. a
n_d =: 0 ". (4 16)$"1('        ',"1((8+3*16){."1>n_d))
element_shell_start =. 2 + (s: a) (e.i.1:) (s: ' *ELEMENT_SHELL')
element_shell_end =. (s:(element_shell_start }. a)) (e.i.1:) (s: ' *END')
e_s_d =: element_shell_end {. element_shell_start }. a
e_s_d =: 0 ". (4 8)$"1((2*8)}."1>e_s_d)

which read (more than really necessary of) the data, split it and convert it to numbers (and which also happened to be my first J program). But I couldn't go any further yet.

From: " Bj?rn Helgason " <[EMAIL PROTECTED]>
Subject: Re: [Jprogramming] Jagged array

To understand your problem

Do you need the data in the changed form
   that is do you need the line 61 71 73 to exist after your operation

or
   is it just a temporary operation and what you really need is to know if
the two last numbers are equal so you can report 3 or 4?

If it is the latter and you want to just find out 3 or 4 but not needing to
do the compare you might add a fifth column to hold the number 3 or 4 as
appropriate - assuming that the matrix needs to be around after the
operation of course

Then you could either keep the fourth item in case they are equal or replace
it with something else

It is always better to know the whole prcocess and not just subtask whic may
or may not be needed


----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to