Re: usage of get1Dindex function ...

From: Ufuk Utku Turuncoglu <u.utku.turuncoglu_at_nyahnyahspammersnyahnyah>
Date: Wed Apr 28 2010 - 00:26:30 MDT

Hi,

I converted the procedure as follows,

undef("sort_xy")
procedure sort_xy(x:numeric, y:numeric, eps:numeric, opt:numeric)

local x_old, y_old, x_ind, y_ind, x_eps, y_eps
begin
   ;--- sort x ---
   if (opt .eq. 1) then
     ;--- fix, the arguments of the get1Dindex must unique ---
     x_eps = new(dimsizes(x), typeof(x))
     do i = 0, dimsizes(x)-1
       x_eps(i) = (i+1)*eps
     end do

     ;--- add artifical small number to get unique array ---
     x = x+x_eps

     ;--- sort arrays ---
     x_old = x
     qsort(x)
     x_ind = get1Dindex(x_old, x)
     y = y(x_ind)
   ;--- sort y ---
   else
     ;--- fix, the arguments of the get1Dindex must unique ---
     y_eps = new(dimsizes(y), typeof(y))
     do i = 0, dimsizes(y)-1
       y_eps(i) = (i+1)*eps
     end do

     ;--- add artifical small number to get unique array ---
     y = y+y_eps

     ;--- sort arrays ---
     y_old = y
     qsort(y)
     y_ind = get1Dindex(y_old, y)
     x = x(y_ind)
   end if
end

The x_eps and y_eps are basically contains unique small numbers and
these values are used to generate unique array elements for the
get1Dindex function. I also convert the input data type from float to
double. The x_eps ot y_eps can be also generated by random number
generation functions.

Thanks for your help,

--ufuk

On 4/27/10 10:02 PM, Dennis Shea wrote:
> Hi Ufuk
>
> Actually the "get1Dindex" fuction notes the following:
>
> "The input arguments should contain only unique values. Duplicate
> entries will lead to a fatal error."
>
>
> I ahve attached a script that contains an example.
> It also (I think) illustrates an error in your
> original script. The fact that subscripts are repeated means that
> the reurn size might be different ... thay are!!!.
>
> Good luck
>
>
> On 04/27/2010 12:22 PM, u.utku.turuncoglu@be.itu.edu.tr wrote:
>> Hi,
>>
>> I wrote the following procedure to sort x,y coordinate pair based on
>> selected one. The opt controls the behavior of the sort procedure. If
>> the
>> value is equal to 1 then, it sorts the x values and match the correct y
>> with it.
>>
>> undef("sort_xy")
>> procedure sort_xy(x:numeric, y:numeric, opt:numeric)
>> local x_old, y_old, x_ind, y_ind
>> begin
>> ;--- sort x ---
>> if (opt .eq. 1) then
>> x_old = x
>> qsort(x)
>> x_ind = get1Dindex(x_old, x)
>> y_old = y
>> y = y(x_ind)
>> ;--- sort y ---
>> else
>> y_old = y
>> qsort(y)
>> y_ind = get1Dindex(y_old, y)
>> x_old = x
>> x = x(y_ind)
>> end if
>> end
>>
>> when i run this procedure,
>>
>> xxx = (/ 3, 5, 2, 10, 6, 4, 3 /)
>> yyy = (/ 1, 8, 4, 3 , 7, 6, 2 /)
>> sort_xy(xxx, yyy, 1)
>>
>> it gives the "fatal:Dimension sizes on right hand side of assignment do
>> not match dimension sizes of left hand side" error in the "get1Dindex"
>> call line. The dimension of the arrays y_old and y or x_old and x is
>> same
>> and the second argument is sorted. I could not find the source of
>> problem.
>> Is there any special requirement to use "get1Dindex" function? How can i
>> solve it?
>>
>> Thanks,
>>
>> --ufuk
>>
>>
>
>

-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Wed Apr 28 00:26:42 2010

This archive was generated by hypermail 2.1.8 : Thu Apr 29 2010 - 08:05:27 MDT