Salve a tutti,
ho creato una classe dove però un array non viene assolutamente alterato.
La classe principale è:
codice:
import tools.exception.Exception;
import java.io.File;
public class SintheticBinarySpectrum {
public static void main(String[] args) throws Exception {
File file = new File("/gaia/lte100-3.5-0.0.spec");
ReadNextGenFile results = new ReadNextGenFile(file);
StarMain.Spectrum.lambda = results.getLambda();
StarMain.Spectrum.flux = results.getFlux();
File file2 = new File("/gaia/lte100-2.0-0.0.spec");
ReadNextGenFile results2 = new ReadNextGenFile(file2);
StarSecondary.Spectrum.lambda = results2.getLambda();
StarSecondary.Spectrum.flux = results2.getFlux();
SpectrumInterpolation Interpolation = new SpectrumInterpolation(StarMain.Spectrum.lambda,StarSecondary.Spectrum.flux,StarMain.Spectrum.flux,5.5);
for( int i=0; i<=StarMain.Spectrum.lambda.length -1; i++)
{
System.out.println ("Total flux ("+i+")= " + Interpolation.getSum()[i]);
}
}
}
dove readnextGen è una classe di lettura.
Invece la classe da me creata è:
codice:
import tools.exception.Exception;
import tools.numeric.interpolation.*;
public class SpectrumInterpolation
{
private double [] totalflux;
public SpectrumInterpolation (double[]l, double []f1, double []f2, double s) throws Exception
{
double [] lambda;
double [] flux1 ;
double [] flux2 ;
double shift;
double step;
double points;
lambda=l;
flux1=f1;
flux2=f2;
shift=s;
totalflux = new double[lambda.length];
double [] newlambda = new double[lambda.length];
double [] newflux2 = new double[lambda.length];
for( int i=0; i<lambda.length ; i++)
{
newlambda[i] = lambda[i] + shift;
}
step=lambda[2]-lambda[1];
points=shift/step;
//Interpolazione
Interpolator f = new LinearInterpolator();
f.setSample(lambda,flux2);
for (int i=0; i<lambda.length-shift-1; i++)
{
newflux2[i] = f.getValue(newlambda[i]);
}
if (shift>0)
{
int j=0;
do
{
newflux2[j] = 0 ;
flux1[j]=0;
j++;
} while(j<points);
}
else if (shift<0)
{
int j=lambda.length;
do
{
newflux2[j] = 0;
flux1[j]=0;
j--;
}while(j>lpoints);
}
for (int i=0 ; i<lambda.length; i++)
{
totalflux[i]= flux1[i] + newflux2[i];
}
}
public double[] getSum()
{
return totalflux;
}
}
Non ho inserito le altre classi implicate perchè solo quest'ultima dà problemi. L'array flux1 infatti nn viene assolutamente modificato. Qualcuno magari sa dirmi quale potrebbe essere il problema e come eventualmente risolverlo? Potrebbe essere legato al fatto che java passa gli oggetti per valore? E in tal caso che si fa?