Defining dynamic arrays in a Structure?
Posted: Sun May 04, 2014 11:07 pm
How can one define (and use) an array element of unknown size in a structure ?
I may be a bit dense but I can't figure out how to do something like this in PureBasic gracefully:
The background is I want to parse files - output from NEC, an antenna simulation software - which contains one or more blocks which look like this:
The number of blocks and the length of each block of data is unknown before reading the file.
I may be a bit dense but I can't figure out how to do something like this in PureBasic gracefully:
Code: Select all
Structure Gain
vert.d
hori.d
total.d
EndStructure
Structure Polarization
axialratio.d
tilt.d
sense.s
EndStructure
Structure E
mag.d
phase.d
EndStructure
Structure Angle
theta.d
phi.d
EndStructure
Structure eTheta
Theta.E
EndStructure
Structure ePhi
Phi.E
EndStructure
Structure RaditionPoint
ang.Angle
gain.Gain
pol.Polarization
et.eTheta
ep.ePhi
EndStructure
Structure RadiationStruc
X.b
N.b
D.b
A.b
I1.d
NTH.d
NPH.d
THETS.d
PHIS.d
DTH.d
DPH.d
RFLD.d
GNOR.d
radp.RaditionPoint(,) ;two dimensional array of unknown size
EndStructure
Dim radpat.RadiationStruc(2)
; calculate the required size of the arrays...
Dim a.RaditionPoint(x1,y1)
Dim b.RaditionPoint(x2,y2)
Dim c.RaditionPoint(x3,y3)
;fill a, b, and c with data, e.g. with data from a file...
;assign arrays to "instances" of radpat
radpat(0)\radp = a
radpat(1)\radp = b
radpat(2)\radp = c
For foo = 0 To 2
With radpat(foo)
For i = 0 To ArraySize(\radp() ,1)
For j = 0 To ArraySize(\radp() ,2)
;do something cool with radpat(foo)\radp(i,j)
Next
Next
EndWith
Next
Code: Select all
- - ANGLES - - - POWER GAINS - - - - POLARIZATION - - - - - - E(THETA) - - - - - - E(PHI) - - -
THETA PHI VERT. HOR. TOTAL AXIAL TILT SENSE MAGNITUDE PHASE MAGNITUDE PHASE
DEGREES DEGREES DB DB DB RATIO DEG. VOLTS/M DEGREES VOLTS/M DEGREES
0.00 0.00 -999.99 -1.33 -1.33 0.00000 -90.00 LINEAR 1.96723E-15 4.31 1.28490E-04 184.31
2.00 0.00 -999.99 -0.89 -0.89 0.00000 -90.00 LINEAR 2.06740E-15 12.81 1.35115E-04 192.81
4.00 0.00 -999.99 -0.55 -0.55 0.00000 -90.00 LINEAR 2.14614E-15 21.13 1.40518E-04 201.13
6.00 0.00 -999.99 -0.31 -0.31 0.00000 -90.00 LINEAR 2.19989E-15 29.32 1.44478E-04 209.32
8.00 0.00 -999.99 -0.17 -0.17 0.00000 -90.00 LINEAR 2.22560E-15 37.39 1.46794E-04 217.39
10.00 0.00 -999.99 -0.14 -0.14 0.00000 -90.00 LINEAR 2.22081E-15 45.40 1.47290E-04 225.40
12.00 0.00 -999.99 -0.23 -0.23 0.00000 -90.00 LINEAR 2.18379E-15 53.38 1.45821E-04 233.38
; many lines of data removed
0.00 3.00 -26.95 -1.34 -1.33 0.00000 87.00 LINEAR 6.72465E-06 184.31 1.28314E-04 184.31
2.00 3.00 -26.52 -0.90 -0.89 0.00000 87.00 LINEAR 7.06663E-06 192.80 1.34922E-04 192.80
4.00 3.00 -26.19 -0.56 -0.55 0.00000 87.01 LINEAR 7.33552E-06 201.11 1.40312E-04 201.11
6.00 3.00 -25.98 -0.32 -0.31 0.00000 87.02 LINEAR 7.51923E-06 209.28 1.44266E-04 209.28
8.00 3.00 -25.88 -0.18 -0.17 0.00000 87.03 LINEAR 7.60733E-06 217.35 1.46583E-04 217.35
10.00 3.00 -25.90 -0.15 -0.14 0.00000 87.05 LINEAR 7.59147E-06 225.35 1.47088E-04 225.35
12.00 3.00 -26.04 -0.24 -0.23 0.00000 87.07 LINEAR 7.46576E-06 233.32 1.45638E-04 233.32
; many lines of data removed
0.00 6.00 -26.95 -1.34 -1.33 0.00000 87.00 LINEAR 6.72465E-06 184.31 1.28314E-04 184.31
2.00 6.00 -26.52 -0.90 -0.89 0.00000 87.00 LINEAR 7.06663E-06 192.80 1.34922E-04 192.80
4.00 6.00 -26.19 -0.56 -0.55 0.00000 87.01 LINEAR 7.33552E-06 201.11 1.40312E-04 201.11
6.00 6.00 -25.98 -0.32 -0.31 0.00000 87.02 LINEAR 7.51923E-06 209.28 1.44266E-04 209.28
8.00 6.00 -25.88 -0.18 -0.17 0.00000 87.03 LINEAR 7.60733E-06 217.35 1.46583E-04 217.35
10.00 6.00 -25.90 -0.15 -0.14 0.00000 87.05 LINEAR 7.59147E-06 225.35 1.47088E-04 225.35
12.00 6.00 -26.04 -0.24 -0.23 0.00000 87.07 LINEAR 7.46576E-06 233.32 1.45638E-04 233.32
; etc. etc. etc. etc.