Possible bug in matlab/4dvar/d_std.m

Bug reports, work arounds and fixes

Moderators: arango, robertson

Post Reply
Message
Author
hjsong

Possible bug in matlab/4dvar/d_std.m

#1 Unread post by hjsong »

Hi,

It is not about the ROMS code, but about the matlab code that is included tha package.

In the recent update, the scripts that compute the standard deviation have been changed a lot.
But mis-position of this one line causes very different result.

For the line 204-222 in d_std.m file look like this.

Code: Select all

        for fval = field_list,
          field     = char(fval);           % convert cell to string
          field_avg = [field, '_avg'];      % average field
          field_std = [field, '_std'];      % standard deviation field

          try,
            F = nc_read(ncfile, field, rec);

            Rcount = Rcount + 1;
          catch,
            disp([' D_STD: error while processing, rec = ', num2str(rec)]);
            disp(['        for variable : ', field]);
            disp(['        in file: ', HisFile1]);
            return
          end,

          S.(field_avg) = S.(field_avg) + F;
          S.(field_std) = S.(field_std) + F.^2;
        end,

But 'Rcount = Rcount + 1' on line 212 should be out of the loop. Otherwise, it will be the sum of all records of all variables.
So, this seems to be changed like this

Code: Select all

        for fval = field_list,
          field     = char(fval);           % convert cell to string
          field_avg = [field, '_avg'];      % average field
          field_std = [field, '_std'];      % standard deviation field

          try,
            F = nc_read(ncfile, field, rec);

          catch,
            disp([' D_STD: error while processing, rec = ', num2str(rec)]);
            disp(['        for variable : ', field]);
            disp(['        in file: ', HisFile1]);
            return
          end,

          S.(field_avg) = S.(field_avg) + F;
          S.(field_std) = S.(field_std) + F.^2;
        end,
        Rcount = Rcount + 1;

This is the same in 'd_std_unbalanced.m' and 'd_std_frc.m'.

Thank you.
Hajoon

User avatar
arango
Site Admin
Posts: 1350
Joined: Wed Feb 26, 2003 4:41 pm
Location: DMCS, Rutgers University
Contact:

Re: Possible bug in matlab/4dvar/d_std.m

#2 Unread post by arango »

Yes, good catch :oops: Thank you for reporting this bug. I introduced that bug in :arrow: src:ticket:461 when I updated the Matlab scripts.

Please update...

Post Reply