[netcdf-java] optimise nc.write computer time


I recently implemented netcdf output for a individual based model written in 
java. The idea is to save a number of variable for each individual at each time 
The netcdf output works well, but it takes a lot of time when it writes data in 
the netcdf. 
I wonder if this time could be reduced by gathering all the variables I want to 
save in a single Array before to write it in the netcdf rather than doing it 
separately for each variable, as I do it in my current script (below).
Does anyone has any idea wether it would work, and how to to it?
Many thanks,


    public void writeResults_NetCDF(ArrayList pop) throws Exception {

        ArrayDouble.D2 longitude_Data = new ArrayDouble.D2(1, 
        ArrayDouble.D2 latitude_Data = new ArrayDouble.D2(1, 
        ArrayInt.D2 prof_Data = new ArrayInt.D2(1, drifter.getLength());
        ArrayInt.D2 identification_Data = new ArrayInt.D2(1, 
        ArrayInt.D2 age_Data = new ArrayInt.D2(1, drifter.getLength()); // 
<<<<<<<peut-être viré
        ArrayDouble.D2 E_Data = new ArrayDouble.D2(1, drifter.getLength());
        ArrayDouble.D2 V_Data = new ArrayDouble.D2(1, drifter.getLength());
        ArrayDouble.D2 E_H_Data = new ArrayDouble.D2(1, drifter.getLength());
        ArrayDouble.D2 E_R_Data = new ArrayDouble.D2(1, drifter.getLength());
        ArrayDouble.D2 temperature_Data = new ArrayDouble.D2(1, 
        ArrayDouble.D2 f_Data = new ArrayDouble.D2(1, drifter.getLength());

        for (int p = 0; p < pop.size(); p++) {
            Poissons Po = (Poissons) pop.get(p);
            if (Po.age > 0) {

                longitude_Data.set(0, p, Po.lon);
                latitude_Data.set(0, p, Po.lat);
                prof_Data.set(0, p, (int) Po.depth);
                identification_Data.set(0, p, Po.id);
                age_Data.set(0, p, Po.age);
                E_Data.set(0, p, Po.DEB.E);
                V_Data.set(0, p, Po.DEB.V);
                E_H_Data.set(0, p, Po.DEB.E_H);
                E_R_Data.set(0, p, Po.DEB.E_R);
                temperature_Data.set(0, p, Po.temp);
                f_Data.set(0, p, Po.DEB.f);

                int[] origin = new int[]{0, 0};
                origin[0] = Simulation.compteur_jours_intra_year;

                try {
                    ncOut.write("longitude", origin, longitude_Data);
                    ncOut.write("latitude", origin, latitude_Data);
                    ncOut.write("depth", origin, prof_Data);
                    ncOut.write("fish_identification", origin, 
                    ncOut.write("fish_age", origin, age_Data);

                    ncOut.write("E", origin, E_Data);
                    ncOut.write("V", origin, V_Data);
                    ncOut.write("E_H", origin, E_H_Data);
                    ncOut.write("E_R", origin, E_R_Data);

                    ncOut.write("temperature", origin, temperature_Data);
                    ncOut.write("f", origin, temperature_Data);

                } catch (IOException e) {
            }// si (Po.age > 0)
        }// boucle sur pop

Timothee Brochier
IRD -  BP 1386 - Dakar, Sénégal
tel : 77 807 2414

  • 2014 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdf-java archives: