Clone DimLabels from one wave to another

Average rating
(0 votes)

Thie snippet takes dimension labels from one wave and clones them to another. Useful when labelling output from e.g. MatrixOP or Wavestats/PCST.

// takes DimLabels from wL and clones it to w
// labels as much as possible in case of varying dimension lengths
// optionally one can choose one dimension to be cloned instead of all
function CloneDimLabels(wL,w [,dim])
	wave wL, w
	variable dim
 
	variable nDim, i, npntsL, npnts, minPnts
 
	// run through all four dimensions
	for(nDim=0; nDim<3; nDim+=1)
 
		if(!ParamIsDefault(dim))
			// if dim is specified, skip all others
			if(nDim != dim)
				continue
			endif
		endif
 
		// check if a dimension exists in both waves
		npntsL = DimSize(wL, nDim)
		npnts = DimSize(w, nDim)
 
		if(npntsL > 0 && npnts > 0)
			// compare dimension size	
			minPnts = min(npntsL, npnts)		
			for(i=0; i<minPnts; i+=1)		
				SetDimLabel nDim, i, $GetDimLabel(wL, nDim, i), w
			endfor
		endif		
	endfor 
 
	return 1
end

Back to top