NCL Home >
Documentation >
Language
Variable Assignment / Reassignment
Consider y = x where x is previously defined. If Y is not defined, then it will have the same shape, values, and meta data as x. If y is already defined, then for the assignment to work, y must already have the same shape as x, and be coercible to that type. Any attributes that y possessed will be overwritten.
Value-only: For variables without metadata, a direct assignment is sufficient:
a = 5
b = (/1,2,3/)
With metadata: the NCL syntax (/.../) will strip away
the metadata:
uval = (/U/)
To reassign a variable to something with a different shape or a
higher type, you must either use the delete
procedure, or the reassignment operator, :=.Using reassignment operator:
x = "This is a string" ; x is a single string
; x = (/1,2,3/) ; This would give you an error
x := (/1,2,3/) ; Now x is a 1D array of integers
Using delete:
x = "This is a string" ; x is a single string
delete(x)
x = (/1,2,3/) ; Now x is a 1D array of integers