[ncl-talk] Problem creating custom colortable

Vollaro, David dvollaro at albany.edu
Thu Mar 8 09:41:12 MST 2018


Hi,


I am having an issue having my NCL script "see" my custom-generated colortable.  I run the script(below) to generate a custom color table, check my NCARG colortable path and check if the table-file is located in my path.  I then plot out the color table and then delete the .rgb file.  The issue is that when I run the script I get the dreaded error


fatal:CvtStringToCmap:Unable to convert string "tstcolx" to ColorMap


If I have an older version of tstcolx.rgb in the color_table dir then it uses that version instead of the newly created one.  It almost seems like NCL generates a listing of all color tables when it is initially called and uses that list when the script runs, ignoring any updates to the color_table directory.  I am running NCL v6.3.0...Thank you



Dave Vollaro


; coltab-make.ncl
; date: 12/16
; Will generate a cusstom color table, copy it to the colortab dir and plot it...



undef("make_coltbl_custom")
;;###########################################################################;;
function make_coltbl_custom(ofile:string,T0:numeric,T[*],icol:numeric,icolor0[3][*]:numeric,opt:logical)
; make_coltab_custom.ncl
; DJV  10/16
; This function will create a Color Table in NCL format
;
begin
  Tk0 = 273+T0              ;temp above which use grayscale
  output = ofile+".rgb"
  ncolor = 239

; ********************  User Temp levels and Colors ***************
  Tk = T+273
  Tloc = new((/icol/),"integer")
  icolor = icolor0*255
; *********** establish output color array and initialize **********
  colors = new((/ncolor,3/), "float")
  colors(:,0) = 0
  colors(:,1) = 0
  colors(:,2) = 0

; white and black occupy locs 0,1
;;#############  Grayscale Definition Section (RGB 0-1) ################
; Find the location of 1st user-override of IR table and set all values
; warmer than Tk0 to grayscale

  if (Tk0.ge.242.5) then
   Bloc = floattoint((247.-Tk0)*2.) + 166
  end if
  if (Tk0.le.242.) then
   Bloc = floattoint(242.-Tk0) + 176
  end if
  print("11st color="+Bloc)
; fspan will interp vals from 1 to 0 over ncolor-2pts.
  colors(2:(Bloc-1), 0) = fspan(2,Bloc-1,Bloc-2)
  colors(2:(Bloc-1), 1) = fspan(2,Bloc-1,Bloc-2)
  colors(2:(Bloc-1), 2) = fspan(2,Bloc-1,Bloc-2)
;;################### END GRAYSCALE DEFINITION  ####################

;;#############  COLOR DEFINITION SECTION (RGB 0-1) ################
  do i=0,icol-1
   if (Tk(i).ge.242.5) then
    Tloc(i) = floattoint((247.-Tk(i))*2.) + 166
   end if
   if (Tk(i).le.242.) then
    Tloc(i) = floattoint(242.-Tk(i)) + 176
   end if
   if (i.eq.0.and.T(i).eq.999) then
    Tloc(i) = 0
   end if
   if (i.eq.icol-1.and.T(i).eq.999) then
    Tloc(i) = ncolor
   end if
   print(Bloc+" "+Tloc(i))
   colors( Bloc:(Tloc(i)-1), 0) = icolor(i,0)
   colors( Bloc:(Tloc(i)-1), 1) = icolor(i,1)
   colors( Bloc:(Tloc(i)-1), 2) = icolor(i,2)
   Bloc=Tloc(i)
  end do
;;###################### END COLOR DEFINITION  #####################

  print("ncolors="+ncolor)
  print("# r g b")
  fmtx       = "3(f8.2,1x)"
  opt        = True
  opt at title  = "# r g b"
  opt at tspace = 10
  opt at fout = "fff"
  write_matrix (colors, fmtx, opt)
  sys_cmd = "echo ncolors="+ncolor+" > "+ofile+" ; cat "+opt at fout+" >>"+ofile
  system(sys_cmd)
;;############################ clean up ####################################;;
  sys_cmd = "echo cleaning up "+" ; rm "+opt at fout+"; mv "+ofile+" "+ofile+".rgb"
  system(sys_cmd)
  return(opt)
end

;##############################  MAIN PROGRAM  ###########################;;
begin
 out_type="X11"
; ******************** User def color table section ****************
 rescolor = True       ;If False then will use default IR coltbl
 T0 = 20              ;Grayscale Temp value(warmer temps use grayscale)
 numtemps = 3          ;Number of color temp values
 temps = (/0.,-40.,999./) ;User deff temp values to color 999=go to end
 colors0 = (/(/1,0,0/),(/0,1,0/),(/0,0,1/)/)      ;r,g,b 0-1
 if (rescolor) then
  colfile = make_coltbl_custom("~/NCL/color_tables/tstcolx",T0,temps,numtemps,colors0,rescolor)
  color_table = "~/NCL/color_tables/tstcolx.rgb"
 end if
; ******************************************************************
 print(color_table)
  system("ls -al ~/NCL/color_tables/tst*")
  system("env |grep NCARG")
  wks = gsn_open_wks(out_type, "ddd")
  gsn_define_colormap(wks,"tstcolx")
  gsn_draw_colormap(wks)
 system("\rm -f ~/NCL/color_tables/tstcolx.rgb ")
end



-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20180308/01c69808/attachment.html>


More information about the ncl-talk mailing list