;---------------------------------------------------------------------- ; This function takes a 1D array of anything and removes all the ; duplicates. ;---------------------------------------------------------------------- undef("remove_duplicates") function remove_duplicates(list1[*]) local newlist, nlist, i, ii begin newlist = list1 newlist@_FillValue = "missing" nlist = dimsizes(newlist) do i=0,nlist-1 ii = ind(newlist(i).eq.newlist) if(dimsizes(ii).gt.1) then newlist(ii(1:)) = newlist@_FillValue end if delete(ii) end do ii = ind(.not.ismissing(newlist)) if(.not.any(ismissing(ii))) then return(newlist(ii)) else return(newlist) end if end ;---------------------------------------------------------------------- ; Trim big png, and create thumbnail version of it. ;---------------------------------------------------------------------- undef("process_png") procedure process_png(png_name) begin system("convert -trim " + png_name + ".png " + png_name + ".png") system("convert -geometry 150x150 " + png_name + ".png " + \ png_name + ".sm.png") end ;---------------------------------------------------------------------- ; This function generates a bullseye array ;---------------------------------------------------------------------- undef("bullseye_array") function bullseye_array(M) local ispn, jspn begin ;---Generate dummy bullseye data for contour plot ispn = conform_dims((/M,M/),ispan(-M/2,M/2,1)^2,1) jspn = conform_dims((/M,M/),ispan(-M/2,M/2,1)^2,0) T = 100. - sqrt(64*(jspn + ispn)) ;---Add coordinate arrays T!0 = "y" T!1 = "x" T&x = fspan(min(ispn),max(ispn),M) T&y = fspan(min(ispn),max(ispn),M) return(T) end ;---------------------------------------------------------------------- ; This function draws a labelbar of the given colormap. ; ; Three images are generated: a large one, a small one, and a ; 500 pixel width one for the web page. ;---------------------------------------------------------------------- undef("labelbar_colormap") procedure labelbar_colormap(cmap_name,opt) local height, lbres begin ;---Set various options based on "opt" vertical = get_res_value_keep(opt,"vertical",False) reverse = get_res_value_keep(opt,"reverse",False) title = get_res_value_keep(opt,"title",True) wks_type = get_res_value_keep(opt,"wks_type","png") wks_dir = get_res_value_keep(opt,"wks_dir","./") wks_name_tmp = cmap_name + "_labelbar" wks_name = wks_dir + get_res_value_keep(opt,"wks_name",wks_name_tmp) ;---Read color map cmap = read_colormap_file(cmap_name) clen = dimsizes(cmap(:,0)) if(reverse) then wks_name_lg = wks_name + "_rev" cmap = cmap(::-1,:) else wks_name_lg = wks_name end if wks_name_sm = wks_name_lg + ".sm" wks_type_lg = wks_type wks_type_sm = wks_type ; ; Start with a larger image and later trim to 500x500, ; for better looking fonts. ; wks_type_lg@wkWidth = 2000 wks_type_lg@wkHeight = 2000 wks_lg = gsn_open_wks(wks_type_lg,wks_name_lg) wks_sm = gsn_open_wks(wks_type_sm,wks_name_sm) lbres = True txres = True txres@txFontHeightF = 0.015 if(vertical) then lbres@vpHeightF = 1.0 ; full width of viewport lbres@vpWidthF = 0.2 lbres@vpYF = 1.0 ; flush top lbres@vpXF = 0.5-lbres@vpWidthF/2. ; centered lbres@lbOrientation = "vertical" else lbres@vpWidthF = 1.0 ; full width of viewport lbres@vpHeightF = 0.2 lbres@vpXF = 0.0 ; flush right lbres@vpYF = 0.5+(lbres@vpHeightF)/2. ; centered lbres@lbOrientation = "horizontal" txres@txJust = "BottomCenter" if(title) then tposx = 0.5 tposy = lbres@vpYF+0.01 if(.not.reverse) then title_string = cmap_name + " (" + clen + " colors)" else title_string = cmap_name + " (reversed, " + clen+ " colors)" end if end if end if lbres@lbLabelsOn = False lbres@lbBoxLinesOn = False ;---Make sure labelbar fills the viewport region we specified lbres@lbBoxMinorExtentF = 1.0 lbres@lbTopMarginF = 0.0 lbres@lbBottomMarginF = 0.0 lbres@lbRightMarginF = 0.0 lbres@lbLeftMarginF = 0.0 lbres@lbPerimOn = True lbres@lbPerimThicknessF = 2.0 lbres@lbPerimColor = "black" ;---necessary so we get all solid fill lbres@lbMonoFillPattern = True lbres@lbFillColors = cmap lbid_lg = gsn_create_labelbar (wks_lg,clen,"",lbres) lbid_sm = gsn_create_labelbar (wks_sm,clen,"",lbres) if(title.and..not.vertical) then txid_lg = gsn_create_text_ndc(wks_lg,title_string,tposx,tposy,txres) end if draw(lbid_lg) if(title.and..not.vertical) then draw(txid_lg) end if ; ; This draws a line around the labelbar. This *might* be to ; force the labelbar to always be a consistent size. ; lnres = True lnres@gsLineThicknessF = 1.5 x = lbres@vpXF y = lbres@vpYF w = lbres@vpWidthF h = lbres@vpHeightF gsn_polyline_ndc(wks_lg,(/x,x+w,x+w,x,x/),(/y,y,y-h,y-h,y/),lnres) frame(wks_lg) draw(lbid_sm) frame(wks_sm) ;---Process PNG ourselves so we can resize it correctly if(wks_type.eq."png") delete(wks_lg) delete(wks_sm) system("convert -trim " + wks_name_lg + ".png " + \ wks_name_lg + ".png") system("convert -trim -geometry 500x500 " + wks_name_sm + ".png " + \ wks_name_lg + ".500.png") system("convert -trim -geometry 130x130 " + wks_name_sm + ".png " + \ wks_name_sm + ".png") end if end ;---------------------------------------------------------------------- ; Create a bullseye color contour map of the given color map. ;---------------------------------------------------------------------- undef("bullseye_colormap") procedure bullseye_colormap(cmap_name,opt) local reverse, i, T, tmin, tmax, res begin ;---Set various options based on "opt" reverse = get_res_value_keep(opt,"reverse",False) title = get_res_value_keep(opt,"title",True) labelbar = get_res_value_keep(opt,"labelbar",False) wks_type = get_res_value_keep(opt,"wks_type","png") wks_dir = get_res_value_keep(opt,"wks_dir","./") wks_name_tmp = cmap_name + "_bullseye" wks_name = wks_dir + get_res_value_keep(opt,"wks_name",wks_name_tmp) cmap = read_colormap_file(cmap_name) clen = dimsizes(cmap(:,0)) if(reverse) then wks_name = wks_name + "_rev" cmap = cmap(::-1,:) end if wks = gsn_open_wks(wks_type,wks_name) T = bullseye_array(25) ;---Generate bullseye array tmin = -30 tmax = 90 res = True res@gsnMaximize = True res@cnFillPalette = cmap res@cnFillOn = True res@cnInfoLabelOn = False res@cnLinesOn = False res@cnLineLabelsOn = False res@gsnTickMarksOn = False res@tmXBBorderOn = True res@tmXTBorderOn = True res@tmYLBorderOn = True res@tmYRBorderOn = True res@lbLabelBarOn = labelbar res@lbBoxLinesOn = False res@cnLevelSelectionMode = "ExplicitLevels" res@cnLevels = fspan(tmin,tmax,clen-1) if(title) then res@tiMainFontHeightF = 0.015 if(.not.reverse) then res@tiMainString = cmap_name + " (" + clen + " colors)" else res@tiMainString = cmap_name + " (reversed, " + clen+ " colors)" end if end if plot = gsn_csm_contour(wks,T,res) if(wks_type.eq."png") delete(wks) process_png(wks_name) end if end ;---------------------------------------------------------------------- ; Generate an MPAS image using the given color map. ;---------------------------------------------------------------------- undef("mpas_colormap") procedure mpas_colormap(cmap_name,opt) begin ;---Set various options based on "opt" reverse = get_res_value_keep(opt,"reverse",False) title = get_res_value_keep(opt,"title",True) wks_type = get_res_value_keep(opt,"wks_type","png") wks_dir = get_res_value_keep(opt,"wks_dir","./") wks_name_tmp = cmap_name + "_mpas" wks_name = wks_dir + get_res_value_keep(opt,"wks_name",wks_name_tmp) cmap = read_colormap_file(cmap_name) clen = dimsizes(cmap(:,0)) if(reverse) then wks_name = wks_name + "_rev" cmap = cmap(::-1,:) end if ;---Read data for contours. dir = "$NCARGTEST/nclscripts/ESMF/data/" filename = dir + "MPAS.nc" f = addfile(filename,"r") sp = f->surface_pressure(0,:) sp = sp/1000. lonCell = f->lonCell latCell = f->latCell ;---Convert to degrees from radians RAD2DEG = 180.0d/(atan(1)*4.0d) ; Radian to Degree lonCell = lonCell*RAD2DEG latCell = latCell*RAD2DEG ;---Start the graphics wks = gsn_open_wks(wks_type,wks_name) res = True ; ; Pick the contour levels based on size of colormap ; spacing = 1.2500 --> 42 levels (43 colors) ; spacing = 0.6250 --> 85 levels (86 colors) ; spacing = 0.3125 --> 170 levels (171 colors) ; if(clen.ge.43.and.clen.lt.86) then res@cnLevelSelectionMode = "ExplicitLevels" res@cnLevels = ispan(525000,1037500,12500)/10000. res@lbLabelStrings = sprintf("%6.3f",res@cnLevels) res@lbLabelJust = "CenterRight" else if(clen.ge.86.and.clen.lt.171) then res@cnLevelSelectionMode = "ExplicitLevels" res@cnLevels = ispan(518750,1043750, 6250)/10000. res@lbLabelStrings = sprintf("%6.3f",res@cnLevels) res@lbLabelJust = "CenterRight" else if(clen.ge.171) then res@cnLevelSelectionMode = "ExplicitLevels" res@cnLevels = ispan(515625,1043750, 3125)/10000. res@lbLabelStrings = sprintf("%6.3f",res@cnLevels) res@lbLabelJust = "CenterRight" else res@cnLevelSelectionMode = "AutomaticLevels" end if end if end if res@gsnMaximize = True res@cnFillOn = True res@cnFillMode = "RasterFill" res@cnFillPalette = cmap res@cnLinesOn = False res@cnLineLabelsOn = False res@mpDataBaseVersion = "MediumRes" res@mpFillOn = True res@mpLandFillColor = -1 res@mpOceanFillColor = "white" res@mpFillDrawOrder = "PostDraw" res@mpMinLatF = -60 res@mpMaxLatF = 70 res@mpMinLonF = -150 res@mpMaxLonF = -30 res@trGridType = "TriangularMesh" ; required res@sfXArray = lonCell res@sfYArray = latCell res@gsnAddCyclic = False res@lbOrientation = "Vertical" res@lbBoxLinesOn = False res@lbLabelFontHeightF = 0.015 res@pmTickMarkDisplayMode = "Always" res@tiMainFontHeightF = 0.02 if(title) then if(.not.reverse) then res@tiMainString = cmap_name + " (" + clen + " colors)" else res@tiMainString = cmap_name + " (reversed, " + clen + " colors)" end if end if plot = gsn_csm_contour_map(wks,sp,res) if(wks_type.eq."png") delete(wks) process_png(wks_name) end if end ;---------------------------------------------------------------------- ; Generate a C.E. image using the given color map. ;---------------------------------------------------------------------- undef("ce_colormap") procedure ce_colormap(cmap_name,opt) local dir, filename, a, sst, levels, labels, res begin ;---Set various options based on "opt" reverse = get_res_value_keep(opt,"reverse",False) title = get_res_value_keep(opt,"title",True) wks_type = get_res_value_keep(opt,"wks_type","png") wks_dir = get_res_value_keep(opt,"wks_dir","./") wks_name_tmp = cmap_name + "_ce" wks_name = wks_dir + get_res_value_keep(opt,"wks_name",wks_name_tmp) cmap = read_colormap_file(cmap_name) clen = dimsizes(cmap(:,0)) if(reverse) then wks_name = wks_name + "_rev" cmap = cmap(::-1,:) end if wks = gsn_open_wks(wks_type,wks_name) ;---Read data for contours. dir = "$NCARGTEST/nclscripts/cdf_files/" filename = dir + "sst8292a.nc" a = addfile(filename,"r") sst = a->SSTA(0,:,:) levels = fspan(-2.4,2.5,clen-1) labels = new(clen-1,string) labels = "" labels(0) = "-2.4" labels(clen-2) = "2.5" ;---Start the graphics res = True res@gsnMaximize = True ; maximize plot in frame res@cnFillPalette = cmap res@cnFillOn = True ; turn on contour fill res@cnLinesOn = False ; turn off contour lines res@cnLineLabelsOn = False ; turn off contour labels res@mpFillDrawOrder = "PostDraw" ; Draw map fill last res@gsnRightString = "" res@gsnLeftString = "" res@mpProjection = "CylindricalEquidistant" res@gsnAddCyclic = True res@mpCenterLonF = 180 res@cnLevelSpacingF = 0.10 res@lbBoxLinesOn = False res@pmLabelBarWidthF = 0.8 res@cnLevelSelectionMode = "ExplicitLevels" res@cnLevels = levels res@lbLabelStrings = labels res@lbLabelAutoStride = False res@cnFillMode = "RasterFill" res@cnRasterSmoothingOn = True res@lbLabelAlignment = "InteriorEdges" if(title) then if(.not.reverse) then res@tiMainString = cmap_name + " (" + clen + " colors)" else res@tiMainString = cmap_name + " (reversed, " + clen + " colors)" end if end if plot = gsn_csm_contour_map(wks,sst,res) if(wks_type.eq."png") delete(wks) process_png(wks_name) end if end ;---------------------------------------------------------------------- ; Generate an EASE image using the given color map. ;---------------------------------------------------------------------- undef("ease_colormap") procedure ease_colormap(cmap_name,opt) local ease_file, lat2d, lon2d, res begin ;---Set various options based on "opt" reverse = get_res_value_keep(opt,"reverse",False) title = get_res_value_keep(opt,"title",True) wks_type = get_res_value_keep(opt,"wks_type","png") wks_dir = get_res_value_keep(opt,"wks_dir","./") wks_name_tmp = cmap_name + "_ease" wks_name = wks_dir + get_res_value_keep(opt,"wks_name",wks_name_tmp) cmap = read_colormap_file(cmap_name) clen = dimsizes(cmap(:,0)) if(reverse) then wks_name = wks_name + "_rev" cmap = cmap(::-1,:) end if wks = gsn_open_wks(wks_type,wks_name) ease_file = addfile("EASE.nc","r") lat2d = ease_file->latitude lon2d = ease_file->longitude yyyymm = 200502 date = ease_file->date nt = ind(date.eq.yyyymm) swe2d = ease_file->SWE(nt,:,:) res = True ; Plot modes desired. res@gsnMaximize = True ; Maximize plot res@cnFillPalette = cmap res@cnFillOn = True ; color plot desired res@cnLinesOn = False ; turn off contour lines res@cnLineLabelsOn = False ; turn off contour lines res@cnFillMode = "RasterFill" ; turn raster on res@trGridType = "TriangularMesh" res@cnInfoLabelOn = False res@gsnRightString = "" res@gsnLeftString = "" res@cnLevelSpacingF = 25 res@lbOrientation = "Vertical" res@pmLabelBarOrthogonalPosF = -0.01 res@mpCenterLonF = 90 res@gsnPolar = "NH" ; specify the hemisphere res@mpMinLatF = 35 res@mpFillOn = False res@mpOutlineOn = False res@mpGridAndLimbOn = False res@gsnAddCyclic = False res@sfXArray = lon2d res@sfYArray = lat2d res@cnFillMode = "RasterFill" res@gsnTickMarksOn = False res@tiMainFontHeightF = 0.015 if(title) then if(.not.reverse) then res@tiMainString = cmap_name + " (" + clen + " colors)" else res@tiMainString = cmap_name + " (reversed, " + clen + " colors)" end if end if plot = gsn_csm_contour_map_polar(wks,swe2d,res) if(wks_type.eq."png") delete(wks) process_png(wks_name) end if end ;---------------------------------------------------------------------- ; Generate an topo image of the Tibean region using the given color map. ;---------------------------------------------------------------------- undef("tibet_colormap") procedure tibet_colormap(cmap_name,opt) begin ;---Set various options based on "opt" reverse = get_res_value_keep(opt,"reverse",False) title = get_res_value_keep(opt,"title",True) wks_type = get_res_value_keep(opt,"wks_type","png") wks_dir = get_res_value_keep(opt,"wks_dir","./") wks_name_tmp = cmap_name + "_tibet" wks_name = wks_dir + get_res_value_keep(opt,"wks_name",wks_name_tmp) cmap = read_colormap_file(cmap_name) clen = dimsizes(cmap(:,0)) if(reverse) then wks_name = wks_name + "_rev" cmap = cmap(::-1,:) end if wks = gsn_open_wks(wks_type,wks_name) dir = "$NCARGTEST/nclscripts/cdf_files/" filename = dir + "ETOPO2_GLOBAL_2_ELEVATION.nc" ; NGDC zcrit = 1500 ; user specifed elevation boundary for Tibet latS = 25 ; rough box that encloses the Tibet Plateau latN = 42 ; this is larger than the 'final' Tibet region lonW = 72 ; common TIBET region: 28N-40N and 75-104E lonE = 108 ; ; Read global grid [180W to 180E] ; ELEV: [LAT | 5401] x [LON | 10801] *includes* cyclic pt ; f = addfile(filename,"r") Z = short2flt( f->ELEV(:,0:10799) ) ; Do not read the cyclic pt ztibet = Z({latS:latN}, {lonW:lonE}) ztibet = where(ztibet .lt.zcrit, ztibet@_FillValue , ztibet ) ;---Start the graphics res = True res@gsnMaximize = True res@gsnAddCyclic = False ; region only res@cnFillMode = "RasterFill" res@cnLinesOn = False ; Turn off contour lines res@cnLineLabelsOn = False ; Turn off contour labels res@cnFillOn = True ; Turn on contour fill res@cnFillPalette = cmap outer_mnlvl = 1600 outer_mxlvl = 5800 outer_levels = fspan(outer_mnlvl,outer_mxlvl,clen+1) ; data goes from 1500 to 8593 levels = outer_levels(1:clen-1) labels = new(clen+1,string) labels = "" labels(0) = "" + outer_mnlvl labels(clen) = "" + outer_mxlvl ; res@cnLevelSelectionMode = "ManualLevels" ; set manual contour levels ; res@cnMinLevelValF = zcrit ; set min contour level ; res@cnMaxLevelValF = 5750 ; set max contour level ; res@cnLevelSpacingF = 125 ; 50, 100 don't make much difference res@cnLevelSelectionMode = "ExplicitLevels" res@cnLevels = levels res@lbLabelStrings = labels res@lbLabelAutoStride = False res@lbLabelAlignment = "ExternalEdges" res@mpMinLatF = latS res@mpMaxLatF = latN res@mpMinLonF = lonW res@mpMaxLonF = lonE res@mpCenterLonF = (lonW+lonE)*0.5 res@mpFillOn = False res@pmLabelBarWidthF = 0.8 if(title) then if(.not.reverse) then res@tiMainString = cmap_name + " (" + clen + " colors)" else res@tiMainString = cmap_name + " (reversed, " + clen + " colors)" end if end if plot = gsn_csm_contour_map_ce(wks,ztibet,res) if(wks_type.eq."png") delete(wks) process_png(wks_name) end if end ;---------------------------------------------------------------------- ; Generate contours on HOMME grid using the given color map. ;---------------------------------------------------------------------- undef("homme_colormap") procedure homme_colormap(cmap_name,opt) begin ;---Set various options based on "opt" reverse = get_res_value_keep(opt,"reverse",False) title = get_res_value_keep(opt,"title",True) full_colormap = get_res_value_keep(opt,"full_colormap",False) wks_type = get_res_value_keep(opt,"wks_type","png") wks_dir = get_res_value_keep(opt,"wks_dir","./") wks_name_tmp = cmap_name + "_homme" wks_name = wks_dir + get_res_value_keep(opt,"wks_name",wks_name_tmp) cmap = read_colormap_file(cmap_name) clen = dimsizes(cmap(:,0)) if(reverse) then wks_name = wks_name + "_rev" cmap = cmap(::-1,:) end if wks = gsn_open_wks(wks_type,wks_name) ; sfile = addfile("b1850cam5cn_camse_01_climo_partial.nc","r") sfile = addfile("b1850cam5cn_camse_01_climo.nc","r") t = sfile->T850(0,:) ; ncol lat = sfile->lat ; ncol lon = sfile->lon ; ncol if(full_colormap) then levels = fspan(238,297,clen-1) labels = new(clen-1,string) labels = "" labels(0) = "240" labels(clen-2) = "296" end if res = True ; Plot mods desired res@gsnMaximize = True ; Maximize plot res@cnFillPalette = cmap res@cnFillOn = True ; color plot desired res@cnInfoLabelOn = False res@cnLinesOn = False ; turn off contour lines res@cnLineLabelsOn = False ; turn off contour labels res@lbLabelBarOn = False res@mpFillOn = False res@mpPerimOn = False res@mpProjection = "Orthographic" res@mpCenterLatF = 70 res@gsnAddCyclic = False res@sfXArray = lon res@sfYArray = lat res@tiMainFontHeightF = 0.015 res@gsnRightString = "" res@gsnLeftString = "" if(full_colormap) then res@cnFillMode = "RasterFill" ; faster if large colormap res@cnRasterSmoothingOn = True res@cnLevelSelectionMode = "ExplicitLevels" res@cnLevels = levels if(isatt(res,"lbLabelBarOn").and.res@lbLabelBarOn.or.\ .not.isatt(res,"lbLabelBarOn")) then res@lbLabelStrings = labels res@lbLabelAutoStride = False res@lbBoxLinesOn = False end if end if if(title) then if(.not.reverse) then res@tiMainString = cmap_name + " (" + clen + " colors)" else res@tiMainString = cmap_name + " (reversed, " + clen + " colors)" end if end if plot = gsn_csm_contour_map(wks,t,res) if(wks_type.eq."png") delete(wks) process_png(wks_name) end if end ;---------------------------------------------------------------------- ; This function draws a table of the given colormap, with the entries ; going from top-to-bottom, left-to-right. ; ; Use table_across_colormap if you want left-to-right, top-to-bottom. ; ; These two table procedures are slightly different:. ; ; table_across_colormap draws the colormap from scratch, and has ; a title. Color indexes 0 and 1 are NOT drawn. This one always ; generates a thumbnail, which doesn't have any labels on it. ; THIS IS THE RECOMMENDED ONE TO USE IN GENERAL. ; ; table_down_colormap uses gsn_draw_colormap, and hence there's ; no title. Color indexes 0 and 1 are drawn. The thumbnail ; is just a smaller version of the full-sized image. ;---------------------------------------------------------------------- undef("table_down_colormap") procedure table_down_colormap(cmap_name,opt) begin ;---Set various options based on "opt" reverse = get_res_value_keep(opt,"reverse",False) wks_type = get_res_value_keep(opt,"wks_type","png") wks_dir = get_res_value_keep(opt,"wks_dir","./") wks_name_tmp = wks_dir + cmap_name + "_table_down" wks_name = get_res_value_keep(opt,"wks_name",wks_name_tmp) if(reverse) then wks_name = wks_name + "_rev" wks = gsn_open_wks(wks_type,wks_name) gsn_define_colormap(wks,cmap_name) gsn_reverse_colormap(wks) else wks = gsn_open_wks(wks_type,wks_name) gsn_define_colormap(wks,cmap_name) end if gsn_draw_colormap(wks) if(wks_type.eq."png") delete(wks) process_png(wks_name) end if end ;---------------------------------------------------------------------- ; This function draws a table of the given colormap, with the entries ; going from left-to-right, top-to-bottom. ; ; Use table_down_colormap if you want top-to-bottom, left-to-right. ; ; These two table procedures are slightly different:. ; ; table_across_colormap draws the colormap from scratch, and has ; a title. Color indexes 0 and 1 are NOT drawn. This one always ; generates a thumbnail, which doesn't have any labels on it. ; THIS IS THE RECOMMENDED ONE TO USE IN GENERAL. ; ; table_down_colormap uses gsn_draw_colormap, and hence there's ; no title. Color indexes 0 and 1 are drawn. The thumbnail ; is just a smaller version of the full-sized image. ;---------------------------------------------------------------------- undef("table_across_colormap") procedure table_across_colormap(cmap_name,opt) local wtype,nrows, ncols, ncolors, maxcolors, ntotal, width, height, \ xpos, ypos, xbox, ybox, hcenter, vcenter begin ;---Set various options based on "opt" reverse = get_res_value_keep(opt,"reverse",False) title = get_res_value_keep(opt,"title",True) wks_type = get_res_value_keep(opt,"wks_type","png") wks_dir = get_res_value_keep(opt,"wks_dir","./") wks_name_tmp = cmap_name + "_table_across" wks_name = wks_dir + get_res_value_keep(opt,"wks_name",wks_name_tmp) ;---Read color map cmap = read_colormap_file(cmap_name) clen = dimsizes(cmap(:,0)) if(reverse) then wks_name_lg = wks_name + "_rev" cmap = cmap(::-1,:) else wks_name_lg = wks_name end if wks_name_sm = wks_name_lg + ".sm" wks_type_lg = wks_type wks_type_sm = wks_type ; ; Start with a larger image and later trim to 500x500, ; for better looking fonts. ; wks_type_lg@wkWidth = 2000 wks_type_lg@wkHeight = 2000 wks_lg = gsn_open_wks(wks_type_lg,wks_name_lg) wks_sm = gsn_open_wks(wks_type_sm,wks_name_sm) hcenter = False ; Center colormap horizontally. vcenter = False ; Center colormap vertically. maxrc = 16 ; max # of cols/rows per page ncols = 16 ; # of columns of colors per page. maxcolors = 256 ; max # of colors per color table. ;---Figure out how many nrows we have, based on ncols. nrows = toint(clen/ncols) if(ncols*nrows.lt.clen) nrows = nrows+1 end if ntotal = nrows * ncols ; # of colors ; ; If you need all color map images to be the same size in the HTML ; page, so they line up nicely, then draw a background in white ; here. This should probably just be for the thumbnail images. ; gnres = True gnres@gsFillColor = "white" ; gsn_polygon_ndc(wks_lg,(/0,1,1,0,0/),(/0,0,1,1,0/),gnres) gsn_polygon_ndc(wks_sm,(/0,1,1,0,0/),(/0,0,1,1,0/),gnres) ; ; X and Y positions of text and box in the view port. ; ; Fix the width/height to accommodate maxrc columns/rows. ; if(title) then top_margin = 0.1 ; leave room for title else top_margin = 0.0 end if top_margin2 = top_margin/2. top = 1.0 - top_margin width = (1.-top_margin)/maxrc height = width xpos = fspan(top_margin2,1-top_margin2-width,maxrc) ypos = fspan(top-height,0,maxrc) ; ; Since we may not have maxrc columns, and we want to center the ; colormap, figure out how much white space we have left over, ; divide in half, and add this to xpos. ; if(hcenter.and.clen.lt.maxrc) then remain_width = 1. - clen*width xpos = xpos + remain_width/2. end if ; ; And, if we have fewer than maxrc colors, then we need to center ; vertically as well. ; if(vcenter.and.nrows.lt.maxrc) then remain_height = 1. - nrows*height ypos = ypos - remain_height/2. end if ;---Box coordinates. xbox = (/0,width, width, 0,0/) ybox = (/0, 0,height,height,0/) font_height = 0.015 font_space = font_height/2. gonres = True ; variables to hold list of resources lineres = True txres = True txres@txFontHeightF = font_height txres@txFont = "helvetica-bold" txres@txJust = "BottomLeft" txres@txFontColor = "black" txres@txBackgroundFillColor = "white" lineres@gsLineColor = "black" ;---Title at top (don't put title on thumbnail) if(title) then txres@txJust = "CenterCenter" txres@txFontHeightF = font_height*2. str = cmap_name + " (" + clen + " colors)" gsn_text_ndc(wks_lg,str,0.5,1.-top_margin2,txres) end if txres@txJust = "BottomLeft" txres@txPerimOn = True txres@txPerimColor = "black" txres@txFontHeightF = font_height ;---Loop through columns first, then rows ii = 0 ; do i=1,min((/ntotal,clen/)),ncols do i=1,ntotal,ncols jj = 0 ; do j=i,min((/i+ncols-1,clen/)) ;---Draw box and fill in the appropriate color. do j=i,i+ncols-1 if(j.le.clen) then gonres@gsFillColor := cmap(j-1,:) ;---Don't draw background/foreground boxes for thumbnails gsn_polygon_ndc(wks_sm,xbox+xpos(jj),ybox+ypos(ii),gonres) gsn_polygon_ndc(wks_lg,xbox+xpos(jj),ybox+ypos(ii),gonres) else ; ; This is for really small colormaps that only take up one row. ; Make sure they are the same size as the rest of the thumbnails ; by filling out the rest of the columns in white. Only need to ; do this for thumbnails. ; if(clen.lt.ncols) then gonres@gsFillColor := "white" ; gsn_polygon_ndc(wks_lg,xbox+xpos(jj),ybox+ypos(ii),gonres) gsn_polygon_ndc(wks_sm,xbox+xpos(jj),ybox+ypos(ii),gonres) lineres@gsLineColor = "gray95" lineres@gsLineThicknessF = 0.1 ; gsn_polyline_ndc(wks_lg,xbox+xpos(jj),ybox+ypos(ii),lineres) gsn_polyline_ndc(wks_sm,xbox+xpos(jj),ybox+ypos(ii),lineres) delete(lineres@gsLineThicknessF) end if end if ; ; Outline box in black. This is commented out because I decided I ; didn't like the box in regardless of thumbnail or not. ; ; gsn_polyline_ndc(wks_lg,xbox+xpos(jj),ybox+ypos(ii),lineres) ; ;---Draw index label. Don't draw labels for index colors > 255 if(j.le.clen.and.j.lt.255) then gsn_text_ndc(wks_lg,j+1,font_space+xpos(jj),ypos(ii)+font_space,txres) end if jj = jj +1 end do ii = ii + 1 end do frame(wks_lg) frame(wks_sm) ;---Process PNG ourselves, since we have two of them if(wks_type.eq."png") delete(wks_lg) delete(wks_sm) system("convert -trim -geometry 500x500 " + wks_name_lg + ".png " + \ wks_name_lg + ".png") system("convert -trim -geometry 130x130 " + wks_name_sm + ".png " + \ wks_name_sm + ".png") end if end ;---------------------------------------------------------------------- ; Creates a plot using the given color map, and the type of plot ; desired. The valid plot types are (case insensitive): ; ; vertical_labelbar ; horizontal_labelbar (default) (labelbar) ; homme ; ease ; tibet ; ce ; bullseye ; table_across (table) ; table_down ;---------------------------------------------------------------------- undef("draw_colormap") procedure draw_colormap(cmap_name,opt) local valid_types, def_plot_type, plot_type begin valid_types = (/"labelbar","vertical_labelbar","horizontal_labelbar",\ "table","table_down","table_across","mpas", \ "homme","ease","tibet","ce","bullseye"/) def_plot_type = "labelbar" ; if no valid one is specified if(opt.and.isatt(opt,"type")) then if(.not.any(opt@type.eq.valid_types)) then print("draw_colormap: Error, invalid type '" + opt@type + "'.") print("Will use '" + def_plot_type) plot_type = def_plot_type else plot_type = opt@type end if else plot_type = def_plot_type end if if(plot_type.eq."vertical_labelbar") then opt@vertical = True labelbar_colormap(cmap_name,opt) end if if(plot_type.eq."labelbar".or.plot_type.eq."horizontal_labelbar") then opt@vertical = False labelbar_colormap(cmap_name,opt) end if if(plot_type.eq."homme") then homme_colormap(cmap_name,opt) end if if(plot_type.eq."ease") then ease_colormap(cmap_name,opt) end if if(plot_type.eq."tibet") then tibet_colormap(cmap_name,opt) end if if(plot_type.eq."mpas") then mpas_colormap(cmap_name,opt) end if if(plot_type.eq."ce") then ce_colormap(cmap_name,opt) end if if(plot_type.eq."bullseye") then bullseye_colormap(cmap_name,opt) end if if(plot_type.eq."table_down") then table_down_colormap(cmap_name,opt) end if if(plot_type.eq."table_across".or.plot_type.eq."table") then table_across_colormap(cmap_name,opt) end if end