Olá pessoal,
Estou trabalhando com matrizes multidimensionais e surgiu uma dúvida que não consigo resolver. Vou tentar resumir o que já fiz e com o problema que me deparei. Primeiro trabalho com o IDL e JAVA. IDL é uma linguagem de descrição de interface.
No IDL precisei realizar o seguinte:
Ler dois arquivos .sav e cnj, onde esses arquivos são matrizes do tipo DOUBLE = Array[4, 16, 16, 16] . Precisei colocar esses dois arquivos em um único, no caso um arquivo binário. (ok - feito)
Depois no JAVA leio esse binário e reestruturo em uma nova matriz também do tipo [4, 16, 16, 16] (ok - feito)
No entanto, agora me deparei com o seguinte problema a matriz [4, 16, 16, 16] possui dimensões variaveis de acordo com o arquivo lido lá no IDL, ou seja, a matriz ficaria assim [4, X, X, Y], onde X e Y são as dimensões que podem variar.
O que eu fiz foi o seguinte, no IDL eu gravo no arquivo binário as posições dessas dimensões para depois receber lá no JAVA, para que vocês possam ver segue meu código no IDL:
PRO READ_FILE
; ---------------------
; Lendo o arquivo .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
; ---------------------
; Lendo o arquivo .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
; ------------------------------------
; Restaurando os arquivos .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'
; ------------------------------------------------------------------
; Salvando em novo arquivo, criando o arquivo binário
; ------------------------------------------------------------------
OpenW, Unit, 'C:\Documents and Settings\Projeto_Estudo\data.bin', /Get_lun, /SWAP_IF_LITTLE_ENDIAN
;-----------------------------------------------------------------------------------------------------------------
; Comparando dimensões e salvando as posições mod_imag[1], mod_imag[3] no arquivo 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: Dimensao de .sav e cnj'
stop
endelse
writeu, unit, modelo.imag
close, unit
END
E meu código JAVA:
import java.io.DataInputStream;
import java.io.File;
import java.io.FileInputStream;
public class LeituraArquivo {
public static void main(String args[]) {
// Declarando a matriz mat
double mat[][][][] = new double[4][16][16][16];
// Chama o metodo lerArquivoBin()
mat=lerArquivoBin("C:/Documents and Settings/Web/IDLWorkspace/Projeto_Estudo/data.dtb");
// Imprimindo a matriz 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[][][][] lerArquivoBin(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("Erro ao ler arquivo: "+origem);
e.printStackTrace();
aux = null;
}
return(aux);
}
}
Daí pensei em fazer algo assim, ler o binário no Java, pegar o valor das posições mod_imag[1], mod_imag[3] e guardar em uma variavel, e depois usar no for
Exemplo: [code]
X= mod_imag[1];
Y = mod_imag[3];
double mat[][][][] = new double[4][X][X][Y];
[/code]
Só que sei também que as posições mod_imag[1], mod_imag[3] são do tipo LONG no IDL.
Alguém pode me ajudar?
Obrigada