Menu

input(...,mode="binary"). How to load triples?

Help
gustaf
2014-08-01
2014-08-02
  • gustaf

    gustaf - 2014-08-01

    The file u2.bin was written by means of a Delphi program. In that program the file was declared

    vector = array [1..3] of double; // Delphi
    binFile = file of vector; // Delphi end

    A vector x is declared and successively assigned and written 22 times. After the file has been closed, then it is checked by means of

    assignFile(fb,'u2.bin'); reset(fb); // Delphi
    writeln; writeln('x from the binary file');
    while not eof(fb) do begin
    read(fb,x);
    vectlib.writeVector(' ',' ',x);
    end{while};
    closeFile(fb); // Delphi end

    This works as expected and 22 vectors (`triples') appear.

    In Asymptote, and since I am new to its file-handling routines, I first made a text version of the binary file and read it successfully. Then I tried to read the binary file. That failed. The Asymptote code is here:

    file bin = input("u2.bin",mode="binary"); // Asymptote
    triple [] u = new triple [22];
    u = bin;
    write(" Array of vector u ",u); // Asymptote end

    Asymptote says that the length of the vector u is zero.

    I tried to read the file bin 22 times by means of for-loop over i and u[i]=bin; Every one of the 22 u[i] was then written as (0,0,0).

    Could anyone guide me out of the impasse?

     
    • Charles Staats

      Charles Staats - 2014-08-01

      Try writing and reading a two-dimensional array of reals (real[][])
      instead of an array of triples.

      On Fri, Aug 1, 2014 at 1:55 AM, gustaf gustaf4711@users.sf.net wrote:

      The file u2.bin was written by means of a Delphi program. In that program
      the file was declared

      vector = array [1..3] of double; // Delphi
      binFile = file of vector; // Delphi end

      A vector x is declared and successively assigned and written 22 times.
      After the file has been closed, then it is checked by means of

      assignFile(fb,'u2.bin'); reset(fb); // Delphi
      writeln; writeln('x from the binary file');
      while not eof(fb) do begin
      read(fb,x);
      vectlib.writeVector(' ',' ',x);
      end{while};
      closeFile(fb); // Delphi end

      This works as expected and 22 vectors (`triples') appear.

      In Asymptote, and since I am new to its file-handling routines, I first
      made a text version of the binary file and read it successfully. Then I
      tried to read the binary file. That failed. The Asymptote code is here:

      file bin = input("u2.bin",mode="binary"); // Asymptote
      triple [] u = new triple [22];
      u = bin;
      write(" Array of vector u ",u); // Asymptote end

      Asymptote says that the length of the vector u is zero.

      I tried to read the file bin 22 times by means of for-loop over i and u[i]=bin;
      Every one of the 22 u[i] was then written as (0,0,0).

      Could anyone guide me out of the impasse?

      input(...,mode="binary"). How to load triples?
      https://sourceforge.net/p/asymptote/discussion/409349/thread/a130bebd/?limit=25#40d5


      Sent from sourceforge.net because you indicated interest in
      https://sourceforge.net/p/asymptote/discussion/409349/

      To unsubscribe from further messages, please visit
      https://sourceforge.net/auth/subscriptions/

       
      • gustaf

        gustaf - 2014-08-02

        Charles,

        With
        file bin = input("u2.bin",mode="binary");
        I tried

        real [][][] u = new real[22][22][22]; u=bin;
        Result: dereference of null array

        real [][][] u ; u=bin;
        Result: dereference of null array

        real [] u = new real [3*22]; u=bin;
        Result: u loads perfectly!

        Thank you for putting me onto the tracks!

         

Log in to post a comment.