Function zeroPad,A,N,M,Center=center ;+ ;B=zeroPad(A,N,M) returns an array B of size NxM such that B[i,j]=A[i,j] ;where A is defined and B[i,j]=0 where A[i,j] is not defined. B is the same ;type as A. ; ;If A is a scalar or a row vector then zeroPad can be called with a single ;dimension argument. B=zeroPad(A,N) returns a row vector of length N. ; ;It is an error if N or M is smaller than the corresponding dimension of A. ; ;KEYWORDS ; ;CENTER: Set the keyword center if the array should be centered in the ;field of zeros. ; ;HISTORY ;Written by H. Rhody September, 1999 ;Modified to include additional error checks and CENTER keyword ;January 2001. ;- sA=Size(A) IF N_Params() LT 2 THEN Message,'Output dimensions not specified' IF N_Params() EQ 2 AND N LT sA[1] THEN $ Message,'Output dimension smaller than input dimension' IF N_Params() EQ 3 THEN IF N LT sA[1] OR M LT sA[2] THEN $ Message,'Output dimension smaller than input dimension' IF N_Params() EQ 2 AND sA[0] EQ 0 THEN BEGIN ;A is a scalar and B is a row vector B=Make_Array(N,TYPE=sA[1]) IF Keyword_Set(center) THEN B[N/2]=A ELSE B[0]=A Return,B End IF N_Params() EQ 2 AND sA[0] EQ 1 THEN BEGIN ;A is a row vector and B is a row vector B=Make_Array(N,TYPE=sA[2]) IF Keyword_Set(center) THEN $ B[(N-sA[1]+1)/2:(N-sA[1]+1)/2+sA[1]-1]=A ELSE $ B[0:sA[1]-1]=A Return,B End ;Output will be a 2D array. Case sA[0] OF 0:Begin ;A is a scalar B=Make_Array(N,M,TYPE=sA[1]) IF Keyword_Set(center) THEN B[N/2,M/2]=A ELSE B[0]=A Return,B End 1:Begin ;1D array B=Make_Array(N,M,TYPE=sA[2]) IF Keyword_Set(center) THEN $ B[(N-sA[1]+1)/2:(N-sA[1]+1)/2+sA[1]-1,M/2]=A $ ELSE B[0:sA[1]-1,0]=A Return,B End 2:Begin ;2D array B=Make_Array(N,M,TYPE=sA[3]) IF Keyword_Set(center) THEN $ B[(N-sA[1]+1)/2:(N-sA[1]+1)/2+sA[1]-1,(M-sA[2]+1)/2:(M-sA[2]+1)/2+sA[2]-1]=A $ ELSE B[0:sA[1]-1,0:sA[2]-1]=A Return,B End EndCase END