Results 1 to 6 of 6
  1. #1
    carol_ana is offline Member
    Join Date
    Nov 2011
    Posts
    3
    Rep Power
    0

    Default Manipulating binary files

    I'm working with multidimensional arrays and i have a question that i can't solve. I'll try to summarize what i've done and the problem that i encountered.
    First i work with IDL and JAVA. IDL is an interface description language.

    In the IDL i did:

    To read 2 files: .sav and .cnj, where these files are arrays of the type DOUBLE = Array[4, 16, 16, 16]. I had to put these 2 files into 1 file , in a binary file. (OK - DONE)


    In the JAVA:

    After in the Java i read this binary and restructures into a new array, also of type [4, 16, 16, 16]. (OK - DONE)


    However, now I came across the following problem, the array [4, 16, 16, 16] has dimensions variable according to the file read in IDL, that is, the array would look like [4, X, X, Y] where X and Y are the dimensions that can vary.
    So, in the IDL i did: i record in binary file the positions of these dimensions.


    you can see my code in IDL :
    Java Code:
    PRO READ_FILE
    
    ; ---------------------
    ; Reading the file .sav
    ; ---------------------
    OpenR, lun, 'C:\Documents and Settings\Projeto_Estudo\I71B16T020.0_B0061_drat0.518_Dlon012.6_Cen0.500_h0.22_base1.00_beta041.9_i021.8_Nel15.00_Blat035_Blong336_fr00001.00_fas15.sav', /Get_lun
    file_sav = strarr(file_lines('C:\Documents and Settings\Projeto_Estudo\I71B16T020.0_B0061_drat0.518_Dlon012.6_Cen0.500_h0.22_base1.00_beta041.9_i021.8_Nel15.00_Blat035_Blong336_fr00001.00_fas15.sav'))
    ReadF, lun, file_sav
    close, lun
    
    ; ---------------------
    ; Reading the file .cnj
    ; ---------------------
    OpenR, lun, 'C:\Documents and Settings\Projeto_Estudo\I71B16T020.0_B0061_drat0.518_Dlon012.6_Cen0.500_h0.22_base1.00_beta041.9_i021.8_Nel15.00_Blat035_Blong336_fr00001.00_fas15.cnj', /Get_lun
    file_cnj = strarr(file_lines('C:\Documents and Settings\Projeto_Estudo\I71B16T020.0_B0061_drat0.518_Dlon012.6_Cen0.500_h0.22_base1.00_beta041.9_i021.8_Nel15.00_Blat035_Blong336_fr00001.00_fas15.cnj'))
    ReadF, lun,file_cnj
    close, lun
    
    ; ------------------------------------
    ; Restoring the files .sav e .cnj
    ; ------------------------------------
    restore, 'C:\Documents and Settings\Projeto_Estudo\I71B16T020.0_B0061_drat0.518_Dlon012.6_Cen0.500_h0.22_base1.00_beta041.9_i021.8_Nel15.00_Blat035_Blong336_fr00001.00_fas15.sav'
    restore, 'C:\Documents and Settings\Projeto_Estudo\I71B16T020.0_B0061_drat0.518_Dlon012.6_Cen0.500_h0.22_base1.00_beta041.9_i021.8_Nel15.00_Blat035_Blong336_fr00001.00_fas15.cnj'
    
    ; ------------------------------------------------------------------
    ; Saving to new file, creating the binary file
    ; ------------------------------------------------------------------
    OpenW, Unit, 'C:\Documents and Settings\Projeto_Estudo\data.bin', /Get_lun, /SWAP_IF_LITTLE_ENDIAN
    
    
    
    ;-----------------------------------------------------------------------------------------------------------------
    ; Comparing dimensions and saving positions mod_imag [1], mod_imag [3] to file data.bin
    ;-----------------------------------------------------------------------------------------------------------------
        conj_imag = size(conjugado.imag, /dim)
        mod_imag = size(modelo.imag, /dim)
        if ((mod_imag[1] eq mod_imag[3]) and (conj_imag[1] eq conj_imag[3])) then begin writeu, unit, mod_imag[1], mod_imag[3]
        endif else begin
            print, 'Error: Dimension of the .sav e cnj'
            stop
        endelse
    
    
    writeu, unit, modelo.imag
    close, unit
    
    END

    My code - JAVA:

    Java Code:
    import java.io.DataInputStream;
    
    import java.io.File;
    import java.io.FileInputStream;
    
    public class LeituraArquivo {
      public static void main(String args[]) {
    
        // Declaring the array mat
        double mat[][][][] =  new double[4][16][16][16];
    
    
       
        // Call the method readFileBin()
         mat=readFileBin("C:/Documents and Settings/Web/IDLWorkspace/Projeto_Estudo/data.bin");
    
    
        // Printing the array mat
        for(int i=0; i< 3; i++) {
                 for(int j=0; j< 15; j++) {
                     for(int k=0; k< 15; k++){
                         for(int l=0; l< 15; l++){
    
                          }
                     }
                 }
               
        }
       
     }
     
     
      public static double[][][][] readFileBin(String origem)
      {
         double aux[][][][] = new double[4][16][16][16];
    
         try{
             File fileOrigin = new File(origem);
             DataInputStream in = new DataInputStream(new FileInputStream(fileOrigin));
            
    
            
             for(int l=0; l< 15; l++) {
                 for(int k=0; k< 15; k++) {
                     for(int j=0; j< 15; j++){
                         for(int i=0; i< 4; i++){
                             aux[i][j][k][l] = (double)in.readDouble();
                             System.out.print(" " + aux[i][j][k][l]);
                             
                         }
                     }
                 }
             }
           
            
             in.close();
         }catch(Exception e){
             System.out.println("Error to read file: "+origem);
             e.printStackTrace();
             aux = null;
         }
         return(aux);
        
    
      }
    }
    Then I thought of doing something, read the binary in Java, get the value of positions mod_imag [1], mod_imag [3] and stored in a variable, and then to use in "for"

    Example:

    Java Code:
    X= mod_imag[1];
    Y = mod_imag[3];
    
    double mat[][][][] =  new double[4][X][X][Y];
    I know that the positions mod_imag [1], mod_imag [3] are of type LONG in IDL.

    If you can help me.
    Thank you!!!

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,558
    Rep Power
    23

    Default Re: Manipulating binary files

    Not sure I understand your problem.
    Are you trying to create a 4 dimensional array in java with data read from a file?

  3. #3
    carol_ana is offline Member
    Join Date
    Nov 2011
    Posts
    3
    Rep Power
    0

    Default Re: Manipulating binary files

    So, these files .sav and .cnj are arrays.

    However, according to the file read in IDL dimensions may vary, where the array would look like [4, X, X, Y] where X and Y are the dimensions that can vary.

    So, in the IDL i did: i record in binary file the positions of these dimensions. I save the positions mod_imag [1], mod_imag [3] to file data.bin (line 34 - 43 in code - IDL)

    Then I thought of doing something, read the binary in Java, get the value of positions mod_imag [1], mod_imag [3]

    Do you understand?

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,558
    Rep Power
    23

    Default Re: Manipulating binary files

    Sorry I don't see where your problem is.
    Does this code that you posted do what you want?
    Java Code:
    X= mod_imag[1];
    Y = mod_imag[3];
     
    double mat[][][][] =  new double[4][X][X][Y];  // create the array with the given dimensions

  5. #5
    carol_ana is offline Member
    Join Date
    Nov 2011
    Posts
    3
    Rep Power
    0

    Default Re: Manipulating binary files

    My problem is ....i have an array of the type [4, 16, 16, 16], but this array can vary dimension, as for example: [4, 17, 17, 15] or [4, 14, 14, 12]. I don't know to do this in JAVA.

    Do you understand?

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,558
    Rep Power
    23

    Default Re: Manipulating binary files

    No, I don't see what your are asking about that is different from what is posted in post #4 and post #1
    Why doesn't the code posted in those posts solve your problem?

Similar Threads

  1. Generating audio files from a binary source
    By _max_ in forum New To Java
    Replies: 2
    Last Post: 10-05-2011, 07:23 AM
  2. writing to binary files
    By TopNFalvors in forum New To Java
    Replies: 10
    Last Post: 03-04-2011, 08:29 AM
  3. Converting mp3 files to binary
    By kylefrank in forum Advanced Java
    Replies: 4
    Last Post: 06-09-2010, 08:25 PM
  4. Read binary files
    By ronaldo121 in forum New To Java
    Replies: 5
    Last Post: 03-04-2010, 03:37 AM
  5. Behaving text files like binary files
    By Farzaneh in forum New To Java
    Replies: 2
    Last Post: 08-27-2008, 03:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •