Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Fortran Programming Language

help assigning array values


Hello, I am writing an euler solver, and I am having trouble with a
seemingly simple operation, which is updating an array at the end of
the process.

if I want to display the current value (pre-update), I run this code:
        print *, U(:,i,j), 'before'
and get the expected output:
   4.000000       4.000000      0.0000000E+00   3.785714     before
the result iterates through a range of i's and j's and spits out many
reasonable numbers

When I want to display the current value along with what the updated
solution should be, I run this code:
        print *, U(:,i,j), 'before'
        print *,  U(:,i,j)-dt*jac(i,j)*((Fp-Fm)+(Gp-Gm)), 'update'
and get this (expected) output, again, only one item in a long list of
numbers is pasted:
   4.000000       4.000000      0.0000000E+00   3.785714     before
   4.004312       4.004308      0.0000000E+00   6.184789     update

Now, if I try to reassign the vector with the new solution, I use this
code:
        print *, U(:,i,j), 'before'
        print *,  U(:,i,j)-dt*jac(i,j)*((Fp-Fm)+(Gp-Gm)), 'update'
        U(:,i,j)= U(:,i,j)-dt*jac(i,j)*((Fp-Fm)+(Gp-Gm))

I get this output:
   4.000000       4.000000      0.0000000E+00   3.785714     before
 NaN            NaN            NaN            NaN            update

The updated value got changed to NaN.  This does not happen for all
iterations, some are NaN, others are normal-looking values, and it
appears seemingly at random.  I even made an explicit loop to do the
reassigning, like so:

        do k=1,4
          U(k,i,j)= U(k,i,j) - dt*jac(i,j)*((Fp(k)-Fm(k))
     &              +(Gp(k)-Gm(k)))

and the output is the same.  Do you have any idea what I am doing
incorrectly?  I apologize for not being able to paste my whole code...
its length does not permit it.

Thank you,
Alex

<a.e.p@gmail.com> wrote:
>         print *, U(:,i,j), 'before'
>         print *,  U(:,i,j)-dt*jac(i,j)*((Fp-Fm)+(Gp-Gm)), 'update'
>         U(:,i,j)= U(:,i,j)-dt*jac(i,j)*((Fp-Fm)+(Gp-Gm))

> I get this output:
>    4.000000       4.000000      0.0000000E+00   3.785714     before
>  NaN            NaN            NaN            NaN            update
...
> and the output is the same.  Do you have any idea what I am doing
> incorrectly?  I apologize for not being able to paste my whole code...
> its length does not permit it.

Nonetheless, the error is probably in the part that you didn't post. The
"obvious" conclusion is that something on the RHS, either dt, jac, Fp,
Fm, Gp, or Gm is a Nan in the cases where this happens. How they got to
be a NaN there is no clue in the code presented. That's not the only
possibility, but it is the first one that comes to mind.

Exceeding array bounds can also do all kinds of strange things. As you
do have arrays, and no evidence relating to teh validity of the index
values, that possibility can't be ignored.

--
Richard Maine                    | Good judgement comes from experience;
email: last name at domain . net | experience comes from bad judgement.
domain: summertriangle           |  -- Mark Twain

The standard advice when you get values that seem to change or act
oddly when you add print statements or change something is that
you should turn on all of the checking options your compiler
supports.  Look for array bounds checking, argument matching,
and undefined variables checks.  Also, most processors have a
floating point option to turn on "instant" faults when a NaN is
generated.  If some variable like dt is a NaN, finding the place where
it becomes a NaN is likely to be the answer.  The "normal" IEEE
mode of letting NaNs silently propagate isn't always the best choice.

Dick Hendrickson

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc