function hsv2rgb (h[*]:float,s[*]:float,v[*]:float) begin ; This procedure converts between HSV and RGB color space ; Input: h [0.0-360.0], s [0.0-1.0], v [0.0-1.0] ; Output: r [0.0-1.0], g [0.0-1.0], b [0.0-1.0] r_g_b = new((/3,dimsizes(h)/),float) r_g_b!0 = "rgb" r_g_b!1 = "cmap_len" if (any((s .eq. 0.0).and.(h.eq.0.0.or.h.eq.360))) then indexs = ind((h.eq.0.0.or.h.eq.360).and.s.eq.0.0) r_g_b(:,indexs) = (/v(indexs),v(indexs),v(indexs)/) delete(indexs) end if f = new(dimsizes(h),float) p = new(dimsizes(h),float) q = new(dimsizes(h),float) t = new(dimsizes(h),float) i = new(dimsizes(h),integer) if any(h.eq.360.0) h(ind(h.eq.360.0)) = 0.0 end if h = h/60.0 i = floattoint(floor(h)) f = h - i p = v*(1.0 - s) q = v*(1.0 - (s*f)) t = v*(1.0 - (s*(1.0 - f))) if any(i.eq.0) then indexs = ind(i.eq.0) r_g_b(:,indexs) = (/v(indexs),t(indexs),p(indexs)/) delete(indexs) end if if any(i.eq.1) then indexs = ind(i.eq.1) r_g_b(:,indexs) = (/q(indexs),v(indexs),p(indexs)/) delete(indexs) end if if any(i.eq.2) then indexs = ind(i.eq.2) r_g_b(:,indexs) = (/p(indexs),v(indexs),t(indexs)/) delete(indexs) end if if any(i.eq.3) then indexs = ind(i.eq.3) r_g_b(:,indexs) = (/p(indexs),q(indexs),v(indexs)/) delete(indexs) end if if any(i.eq.4) then indexs = ind(i.eq.4) r_g_b(:,indexs) = (/t(indexs),p(indexs),v(indexs)/) delete(indexs) end if if any(i.eq.5) then indexs = ind(i.eq.5) r_g_b(:,indexs) = (/v(indexs),p(indexs),q(indexs)/) delete(indexs) end if if(any(ismissing(r_g_b))) print("WARNING: Some invalid HSV values were passed to hsv2rgb") end if return(r_g_b(cmap_len|:,rgb|:)) end