BBC BASIC for Windows
General >> General Board >> Is it possible to save a 3D array to disk
http://bb4w.conforums.com/index.cgi?board=general&action=display&num=1282665154

Is it possible to save a 3D array to disk
Post by Danny72 on Aug 24th, 2010, 3:52pm

Hello everyone,

Could someone let me know if it is possible to save a 3D array to Hard Drive.

e.g.

a$(x,y,z)

If so, could you perhaps let me know the exact code to type in, to save and retrieve array.

Many thanks.

Danny
Re: Is it possible to save a 3D array to disk
Post by admin on Aug 24th, 2010, 10:41pm

on Aug 24th, 2010, 3:52pm, Danny72 wrote:
Could someone let me know if it is possible to save a 3D array to Hard Drive e.g. a$(x,y,z)

As it's a string array the easiest way is to save/load the individual elements:

Code:
      DEF PROCsave3Darray(F%, a$())
      LOCAL I%,J%,K%
      FOR I% = 0 TO DIM(a$(),1)
        FOR J% = 0 TO DIM(a$(),2)
          FOR K% = 0 TO DIM(a$(),3)
            PRINT #F%, a$(I%,J%,K%)
          NEXT
        NEXT
      NEXT
      ENDPROC
      
      DEF PROCload3Darray(F%, a$())
      LOCAL I%,J%,K%
      FOR I% = 0 TO DIM(a$(),1)
        FOR J% = 0 TO DIM(a$(),2)
          FOR K% = 0 TO DIM(a$(),3)
            INPUT #F%, a$(I%,J%,K%)
          NEXT
        NEXT
      NEXT
      ENDPROC 

In each case the first parameter is the file's channel number, as returned from OPENIN, OPENOUT or OPENUP. So for example to save the array you could do:

Code:
      chan% = OPENOUT(@tmp$+"array.dat")
      PROCsave3Darray(chan%, a$())
      CLOSE #chan% 

Richard.

Re: Is it possible to save a 3D array to disk
Post by Danny72 on Aug 25th, 2010, 11:47am

Thank you very much as always.

Danny