Finding unique dates from two arrays [SEC=UNCLASSIFIED]

From: Griffith Young <G.Young_at_nyahnyahspammersnyahnyah>
Date: Wed Oct 10 2012 - 23:25:03 MDT

Dear NCL Talk,

I wrote this because I did not have a function that would get the unique dates from two arrays.

I also noticed that someone had asked for this kind of function back in April.

I probably should have commented the code, but I think what it does is pretty obvious. (Maybe)

============================================================

undef("find_unique_dates")
function find_unique_dates(da1:double, da2:double)
local i1, i2, m1, m2, count, da
begin
    i1 = 0
    i2 = 0
    m1 = dimsizes(da1)
    m2 = dimsizes(da2)
    count = 0
    do while (i1 .lt. m1 .and. i2 .lt. m2)
        if (da1(i1) .eq. da2(i2)) then
            i1 = i1 + 1
            i2 = i2 + 1
        else
            if (da1(i1) .lt. da2(i2)) then
                i1 = i1 + 1
            else
                i2 = i2 + 1
            end if
        end if
        count = count + 1
    end do

    count = count + m1 - i1 + m2 - i2

    da = new (count, "double")
    da = da1(0)

    i1 = 0
    i2 = 0
    count = 0
    do while (i1 .lt. m1 .and. i2 .lt. m2)
        if (da1(i1) .eq. da2(i2)) then
            da(count) = da1(i1)
            i1 = i1 + 1
            i2 = i2 + 1
        else
            if (da1(i1) .lt. da2(i2)) then
                da(count) = da1(i1)
                i1 = i1 + 1
            else
                da(count) = da2(i2)
                i2 = i2 + 1
            end if
        end if
        count = count + 1
    end do

    do while (i1 .lt. m1)
        da(count) = da1(i1)
        i1 = i1 + 1
        count = count + 1
    end do

    do while (i2 .lt. m2)
        da(count) = da2(i2)
        i2 = i2 + 1
        count = count + 1
    end do

    return da
end

============================================================

Regards,
        Griff.
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Oct 10 23:25:16 2012

This archive was generated by hypermail 2.1.8 : Fri Oct 12 2012 - 15:38:19 MDT