Title: Sv_NV(av_shift(AV)) skipping even indices of array

Hello,

I am having trouble converting 2 dimensional arrays in Perl into 2 dimensional arrays of doubles. In the inner loop of the following code, only every odd index of the Timeseries array is printed and then the rest is padded with 0 s. The odd thing is that the outer loop's shift operation does not suffer from this problem.

PPCODE:
       AV* Data;
       …
       double Fortran_Data[num_predictors][length_timeseries];
       ...

       int i,j;
        for(i = 0; i < num_predictors; i++)
        {
            AV* Timeseries = (AV*)SvRV(av_shift(Data));
            for(j = 0; j < length_timeseries; j++)
            {
                Fortran_Data[i][j] = (double)SvNV(av_shift(Timeseries));
                printf("\nFortran_Data at %i at %i = %f\n",i,j,Fortran_Data[i][j]);
            }
        }

I have tinkered with it and the code bellow works properly, although it should be equivalent to the above code. The only modification is holding the result of av_shift(Timeseries) in an intermediate pointer.

PPCODE:
       AV* Data;
       …
       double Fortran_Data[num_predictors][length_timeseries];
       ...

       int i,j;
        for(i = 0; i < num_predictors; i++)
        {
            AV* Timeseries = (AV*)SvRV(av_shift(Data));
            for(j = 0; j < length_timeseries; j++)
            {
                SV* temp = av_shift(Timeseries);
                Fortran_Data[i][j] = (double)SvNV(temp);
                printf("\nFortran_Data at %i at %i = %f\n",i,j,Fortran_Data[i][j]);
            }
        }

Why is this any different? Why does av_shift get called twice in the first one?
I am running Perl with multithreading, so perhaps its that?
I am using gcc for compiling and gfortran for linking.

Any insights would be very appreciated.

-Peter Lobsinger

Reply via email to