;---------------------------------------------------------------------- ; Read an ASCII file that has tabs as delimiters. Because each column ; is separated by a single table, you can use str_split_csv to split ; the columns and get back a 2D array ;---------------------------------------------------------------------- begin tab = str_get_tab() filename = "lightning.txt" lines = asciiread(filename,-1,"string") csv_lines = str_split_csv(lines,tab,0) ; 2D array dimensioned 33 x 9 ;---Print some information about the file dims = dimsizes(csv_lines) nrows = dims(0) ncols = dims(1) printVarSummary(csv_lines) print("======================================================================") print("Filename: " + filename) print(" # of rows = " + nrows) print(" # of columns = " + ncols) print("======================================================================") timestamp = csv_lines(:,0) ; column 0 date = csv_lines(:,1) ; column 1 lat = tofloat(csv_lines(:,2)) ; column 3 lon = tofloat(csv_lines(:,3)) ; column 4 col4 = tofloat(csv_lines(:,4)) col5 = tofloat(csv_lines(:,5)) col6 = tofloat(csv_lines(:,6)) col7 = tofloat(csv_lines(:,7)) ;---Assign some metadata to lat/lon lat@long_name = "latitude" lon@long_name = "longitude" lat@units = "degrees_north" lon@units = "degrees_east" ;---Print information about lat and lon printVarSummary(lat) printVarSummary(lon) printMinMax(lat,0) printMinMax(lon,0) ;---------------------------------------------------------------------- ; Start the graphics ;---------------------------------------------------------------------- wks = gsn_open_wks("png","lightning") ;---Set some resources res = True res@gsnMaximize = True res@gsnDraw = False res@gsnFrame = False res@mpMinLatF = max((/-90,min(lat)-1/)) res@mpMaxLatF = min((/90,max(lat)+1/)) res@mpMinLonF = max((/-180,min(lon)-1/)) res@mpMaxLonF = min((/180,max(lon)+1/)) res@mpFillOn = False res@mpDataBaseVersion = "MediumRes" ; "LowRes", "HighRes" res@pmTickMarkDisplayMode = "Always" ; Gives you nicer tickmarks res@tiMainString = "Lightning strikes" res@tiMainFontHeightF = 0.02 res@gsnStringFontHeightF = 0.01 res@gsnLeftString = "Start: " + timestamp(0) res@gsnRightString = "End: " + timestamp(nrows-1) plot = gsn_csm_map(wks,res) ;---Select font "f" in table 37 which is a lightning symbolx (just for fun) lgtng_marker = NhlNewMarker(wks, "f", 37, 0.0, 0.0, 1.3125, 3., 0.0) ;---Attach markers at each lat/lon location, showing lightning strikes mkres = True mkres@gsMarkerIndex = lgtng_marker id = gsn_add_polymarker(wks,plot,lon,lat,mkres) ;---Drawing the plot will also draw the attached markers draw(plot) frame(wks) end