Where is the last array field ??

Just starting out? Need help? Post your questions and find answers here.
Joris
Addict
Addict
Posts: 885
Joined: Fri Oct 16, 2009 10:12 am
Location: BE

Where is the last array field ??

Post by Joris »

Hi,

Yeah, because I can't attach a file, I had to reform the file to load into the datasection, So you'll first have to creat this.
When loading the file the last ellement isn't filled and I don't know why. I tried many things (but it should be a simple problem..)

Thanks.

Code: Select all

Structure PERF_SETUP   
  prf_CC.a                                                                          
  fdr_CC.a                                                                          
  Chnl.a                                                                            
  prt_idx.a                                                                         
  naam.s{#MAXPNAMELEN}   
EndStructure
Global pcs.PERF_SETUP
Structure PERF  
  CVol.a  
  CTyp.a
  VMsb.a
  VLsb.a
  VDat.a   
  naam.s{#MAXPNAMELEN}
EndStructure
Global Dim prf.PERF(15)      

Procedure Load_Setup(naam.s, *p.PERF_SETUP, Array pc.PERF(1))
  Protected.i open, a, n
  
  If FileSize(naam) 
  
    open = OpenFile(#PB_Any, naam, #PB_File_SharedRead | #PB_UTF8)
    
    If open
      n=ArraySize(pc())
      ReadData(open, *p, SizeOf(PERF_SETUP))
      FileSeek(open, SizeOf(PERF_SETUP),#PB_Absolute) 
      ReadData(open, @pc(0), SizeOf(PERF)*n)
      CloseFile(open)
       
      For a=0 To n
       Debug pc(a)\naam
       ;Debug pc(a)\CTyp
      Next

    EndIf
    ;ShowMemoryViewer(@pc(0), SizeOf(PERF)*n)
  EndIf
  
EndProcedure

;Export_txt("C:\Performance 08.pcm")   ;create the file first
Load_Setup("C:\Performance 08.pcm", @pcs,  prf())


Procedure.s Export_txt(naam.s)   
  Protected Length.i, a.i, open.i, nLines.i, Text.s  
  
  Length = ?Performance_08_pcm_end-?Performance_08_pcm
  Text = PeekS(?Performance_08_pcm, Length,#PB_UTF8)
  open=OpenFile(#PB_Any,"C:\Performance 08.pcm",#PB_File_NoBuffering | #PB_File_SharedRead)  

  If open
    WriteString(open, Text, #PB_UTF8)
    FlushFileBuffers(open)
    CloseFile(open)
  EndIf
  
DataSection
  Performance_08_pcm: 
    ; size : 1172 bytes
    Data.q $00000000FF0007FD,$0000000000000000,$0000000000000000,$0000000000000000,$0000000000000000
    Data.q $0000000000000000,$0000000000000000,$0000000000000000,$0000010000000000,$75006F0063004100
    Data.q $6300690074007300,$6100720047002000,$5000200064006E00,$6F006E0061006900,$0000000000000000
    Data.q $0000000000000000,$0000000000000000,$0043080000010000,$00730065006C0065,$0000000000610074
    Data.q $0000000000000000,$0000000000000000,$0000000000000000,$0000000000000000,$0000000000000000
    Data.q $0100000000000000,$6100720044100000,$7200610062007700,$670072004F002000,$000000006E006100
    Data.q $0000000000000000,$0000000000000000,$0000000000000000,$0000000000000000,$1800000100000000
    Data.q $0075006F00630041,$0063006900740073,$0069007500470020,$0020007200610074,$006C0079006E0028
    Data.q $00000029006E006F,$0000000000000000,$0000000000000000,$6300412000000100,$7400730075006F00
    Data.q $4200200063006900,$0000730073006100,$0000000000000000,$0000000000000000,$0000000000000000
    Data.q $0000000000000000,$0001000000000000,$006F006900562800,$0000006E0069006C,$0000000000000000
    Data.q $0000000000000000,$0000000000000000,$0000000000000000,$0000000000000000,$0000000000000000
    Data.q $5330000001000000,$6E00690072007400,$6E00450020006700,$62006D0065007300,$3100200065006C00
    Data.q $0000000000000000,$0000000000000000,$0000000000000000,$0000000000000000,$0072005438000001
    Data.q $00650070006D0075,$0000000000000074,$0000000000000000,$0000000000000000,$0000000000000000
    Data.q $0000000000000000,$0000000000000000,$0000010000000000,$720070006F005340,$20006F006E006100
    Data.q $0000780061005300,$0000000000000000,$0000000000000000,$0000000000000000,$0000000000000000
    Data.q $0000000000000000,$0050480000010000,$006F006300630069,$00000000006F006C,$0000000000000000
    Data.q $0000000000000000,$0000000000000000,$0000000000000000,$0000000000000000,$0100000000000000
    Data.q $610065004C500000,$2000310020006400,$7500710073002800,$2900650072006100,$0000000000000000
    Data.q $0000000000000000,$0000000000000000,$0000000000000000,$5800000100000000,$0020006400610050
    Data.q $006E002800200031,$0061002000770065,$0000002900650067,$0000000000000000,$0000000000000000
    Data.q $0000000000000000,$0000000000000000,$5800466000000100,$2800200031002000,$6E00690061007200
    Data.q $0000000000002900,$0000000000000000,$0000000000000000,$0000000000000000,$0000000000000000
    Data.q $0001000000000000,$0074006900536800,$0000000000720061,$0000000000000000,$0000000000000000
    Data.q $0000000000000000,$0000000000000000,$0000000000000000,$0000000000000000,$5470000001000000
    Data.q $6C006B006E006900,$6500420020006500,$000000006C006C00,$0000000000000000,$0000000000000000
    Data.q $0000000000000000,$0000000000000000,$0000000000000000,$0075004778000001,$0072006100740069
    Data.q $0065007200460020,$006F004E00200074,$0000006500730069,$0000000000000000,$0000000000000000
    Data.q $0000000000000000
    Data.b $00,$00,$00,$00
  Performance_08_pcm_end:
EndDataSection

EndProcedure 
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
User avatar
Demivec
Addict
Addict
Posts: 4085
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Where is the last array field ??

Post by Demivec »

Joris wrote: Sat Oct 16, 2021 9:26 amWhen loading the file the last ellement isn't filled and I don't know why. I tried many things (but it should be a simple problem..)
The error lies in the calculation of the number of array elements to read in the Load_Setup() procedure:

Code: Select all

;main scope declaration for reference
;Global Dim prf.PERF(15)

;within Load_Setup() procedure:
n=ArraySize(pc())
;n = the dimensioned size and not the number of elements,
; i.e. if Dim pc(15) then ArraySize(pc()) = 15 but
; there are 16 elements indexed from 0 to 15.
; The number of elements is equal to n + 1
ReadData(open, @pc(0), SizeOf(PERF)*n); leaves off last element 
ReadData(open, @pc(0), SizeOf(PERF)*(n + 1)); reads all elements
Last edited by Demivec on Sat Oct 16, 2021 11:57 am, edited 2 times in total.
Joris
Addict
Addict
Posts: 885
Joined: Fri Oct 16, 2009 10:12 am
Location: BE

Re: Where is the last array field ??

Post by Joris »

Demivec thank you.
Yeah I know, but keep in mind ... Leonardo da Vinci was also an autodidact.
Post Reply