[ncl-talk] comform 2 1d vectors to same length

Mary Haley haley at ucar.edu
Fri Feb 3 06:15:42 MST 2017

```Marson,

I didn't see a response to this, but apologies if this is a duplicate.

The issue is that anytime you do an array comparison like:

thour.eq.phour

The two arrays must be exactly the same dimension size.

If I understand what you are asking for, then this code illustration might
help. It shows how to remove elements from x1 that also exist in x2:

x1 = (/1,2,3,4,5,6/)   ; list of numbers we want to remove values from

x2 = (/3,5,7,9/)       ; list of values we want to remove from x1
x1_copy = x1
x1_copy at _FillValue = default_fillvalue(typeof(x1))

;
; Loop through each element in x2 and if it exists
; in x1, then set the corresponding index in x1 to
; missing.                                                         ;

do n=0,dimsizes(x2)-1
ii := ind(x1.eq.x2(n))
if(.not.any(ismissing(ii))) then
x1_copy(ii) = x1_copy at _FillValue
end if
end do

;---Remove all the missing values from x1_copy and assign to new variable

x1_reduced = x1_copy(ind(.not.ismissing(x1_copy)))
print(x1_reduced)    ; should be 1, 2, 4, 6

--Mary

On Thu, Jan 26, 2017 at 9:44 AM, GMAIL <shejo284 at gmail.com> wrote:

> Hi,
>
> I’m trying to conform 2 1D-vectors to the same length but I think the
> comform functions can only handle N-D arrays where N>1. For example:
>
> thour = mask(thour,conform(thour, (phour.eq.thour.and. \
>                                                pyear.eq.oyear.and. \
>                                                pmonth.eq.omonth.and. \
>                                                pday.eq.oday),(/0/)),False),
> where thour and phour, pyear, pmonth, and pday are of slightly different
> lengths (all p* variables have the same length).
> This statement returns an error:
>
> fatal:Eq: Dimension size, for dimension number 0, of operands does not
> match, can't continue.
>
> I know this is a bit of a trick I’m trying that doesn’t seem to work. Is
> there a work-around for doing something like this?
> What I’m trying to do is to remove common times when 2 MHS granules
> overlap.
>
> Any help is appreciated,
> /M
>
>
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20170203/987636a8/attachment.html
```