Re: copying attributes

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Thu, 30 Mar 2006 12:33:19 -0700 (MST)


>I'm trying to copy a variable from one file to another
>and collapse a dimension, to do this I am doing:

> vtype = getfilevartypes(f1,vnames(n))
> filevardef(f2,vnames(n),vtype, newdims)
> v = f1->$vnames(n)$
> f2->$vnames(n)$ = onedtond(ndtooned(v), newdimsizes)
> copy_VarAtts(v , f2->$vnames(n)$)

>It all works (that is there are no errors) but the
>attributes don't get copied - any idea why?

Yes, I do know why.

I suppose you want me to tell you the reason? :-)

[a] "ndtooned" is a builtin function.
     It does not do anything with meta data.
     x = onedtond(ndtooned(v), newdimsizes)
     You will see that no meta data [attributes
     or coordinates] are present. Hence,

     f2->$vnames(n)$ = onedtond(ndtooned(v), newdimsizes)
                       a temporary variable with no meta data
     the vnames(n) variable on f2 will have no attributes.
     The following will not work
     copy_VarAtts(v , f2->$vnames(n)$)
     To accomplish what you want:
        x = onedtond(ndtooned(v), newdimsizes)
        copy_VarAtts(v , x)
        f2->$vnames(n)$ = x
       ;delete(x) ; if you want
>Also is there a function to copy global attributes
>from one file to another without knowing what
>they are called?

 Yes, there is. I speculate you want to how? :-)
 f1 = addfile(...)
 f2 = addfile)...)
f1 and f2 are kinda like waves and particles. They
have a dual nature :-)

 f1/f2 are, in NCL lingo, "references" [aka, pointers
 to the respective files. They are also variables.
      copy_VarAtts( f1, f2)
 will accomplish what you want.
 Also, [Note reversal of argument order]
      fileattdef( f2, f1 )

Good luck

ncl-talk mailing list
Received on Thu Mar 30 2006 - 12:33:19 MST

This archive was generated by hypermail 2.2.0 : Fri Mar 31 2006 - 10:32:28 MST