Log In | Users | Register
Edit | Attach | New | Raw | Diff | Print | | Tools
You are here: Data » DocTools » ToolsVis » VisNCL » VisNCLDictionary

NCL dictionary for Matlab, IDL and R.

A dictionary to translate commands between NCL and other popular scripting languages.

Basics

NCL Matlab IDL R Comment
; % ; # Comment symbol
\ ... $ [not necessary] Line continuation
print(variable) variable print, variable variable Print variable
printVarSummary(variable) whos variable help, variable   Get information on variable

Operators

Arithmetic operators

NCL Matlab IDL R Comment
a=1 a=1 a=1 a<-1 Assignment
a + b - c a + b - c a + b - c a + b - c Addition / Substraction
a * b a .* b a * b a * b Multiplication (element-wise)
a # b a * b a # b a %*% b Multiplication (matrix)
a / b a / b a / b a / b Division
a ^ b a .^ b a ^ b a ^ b Power
a % b rem(a,b) a mod b a %% b Remainder
  factorial(n) factorial(n) factorial(n) Factorial n!

Relational operators

NCL Matlab IDL R Comment
a .eq. b a == b a eq b a == b Equal
a .lt. b a < b a lt b a < b Less than
a .gt. b a > b a gt b a > b Greater than
a .le. b a <= b a le b a <= b Less than or equal
a .ge. b a >= b a ge b a >= b Greater than or equal
a .ne. b a ~= b a ne b a != b Not equal

Logical operators

NCL Matlab IDL R Comment
a .and. b a & b a && b a & b AND
a .or. b a | b a || b a | b OR
a .xor. b xor(a,b)   xor(a,b) Exclusive OR
.not. a ~a ~ a !a NOT

Note: In IDL, and, or, xor, and not are bitwise operators. In the case of using not instead of ~, this can lead to unexpected results. See IDL manual on bitwise operators for more details on this.

Array

Creation

NCL Matlab IDL R Comment
A = (/ (/1,3/), (/7,2/) /) A=[1,3;7,2]; A=[[1,3],[7,2]] A <- rbind(c(1,3),c(7,2)) Create

Access and assignment

NCL Matlab IDL R Comment
A(0,1) A(1,2) A[1,0] A[1,2] First row, second column
A(0,:) A(1,:) A[*,0] A[1,] First row
A(1:,:) A(2:end,:) A[*,1:*] A[-1,] All except first row
A(0::2,:) A(1:2:end,:) A[*,0:*:2] --- Every other row
A(:,0) = 99 A(:,1) = 99 A[0,*] = 99 A[,1] = 99 Assign value to column

Transpose etc.

NCL Matlab IDL R Comment
transpose(A) A'; transpose(A) t(A) Transpose
--- det(A) determ(A) det(A) Determinant
--- inv(A) invert(A) solve(A) Inverse
--- circshift(A,[0 -1]) shift(A,-1,0) ??? Shift to the left by 1

Sum

NCL Matlab IDL R Comment
dim_sum_n(A,1) sum(A) total(A,2) apply(A,2,sum) Sum of each column
dim_sum(A) sum(A') total(A,1) apply(A,1,sum) Sum of each row
sum(A) sum(A(:)) total(A) sum(A) Sum of all elements

Array sizes

NCL Matlab IDL R Comment
dimsizes(A) size(A) size(A) dim(A) Dimensions
product(dimsizes(A)) length(A(:)) n_elements(A) prod(dim(a)) Number of elements
dimsizes(dimsizes(A)) ndims(A) (size(A))[0] dim(dim(A)) Number of dimensions

Control Structures

NCL Matlab IDL R Comment
if (a .gt. 0) then
statements
end if
if a>0
statements
end
if a gt 0 then begin
statements
endif
if (a > 0)
  { statements }
If-statement
if (a .gt. 0) then
statements
else
statements
end if
if a>0
statements
else
statements
end
if a gt 0 then begin
statements
endif else begin
statements
endelse
if (a > 0)
  { statements }
else
  { statements }
If-else-statement
do i=1,10
statements
end do
for i=1:10
statements
end
for i=1,10 do begin
statements
endfor
for (i in 1:10)
  { statements }
For loop
do while (i .lt. 10)
statements
end do
while (i<10)
statements
end
while i lt 10 do begin
statements
endwhile
while (i < 10)
  { statements }
While loop
spacer
This site is managed by the Center for Climate Systems Modeling (C2SM).
This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors. Ideas, requests, problems? Send feedback!