<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style id="owaParaStyle" type="text/css">P {margin-top:0;margin-bottom:0;}</style>
</head>
<body ocsi="0" fpstyle="1">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">Hi NCL-Users<br>
<br>
I am struggling to get my loops to work in a plot I am trying to create for an animation.<br>
<br>
I have u and v wind data that has 7304 timesteps in it and I have a text file of shipping data that I want to use to plot ship tracks for the same wind fields i.e I would like to create 7304 png images to use to create an animation using fmpeg.<br>
<br>
The text file of the shipping data has 252391 timesteps so I only want to extract the data that matches the wind data. So I want to plot ship tracks only every 6 hours.<br>
<br>
The wind data is 4 times daily at 00,06,12,18<br>
The ship data is hourly 00,01,02,03,04 etc..<br>
<br>
I want to create plots to match up with the wind fields i.e. use the winds as the background plot and overlay them with ship tracks using polymarker function in NCL for every 6 hours.<br>
<br>
Below is my script but it is not working correctly.<br>
<br>
If anyone could please advice how to go about fixing it that would be much appreciated.<br>
<br>
Many thanks!<br>
<br>
Kindest Regards<br>
Melissa<br>
<br>
;----------------------------------------------------------------------<br>
; Krakatoa_1.ncl<br>
;----------------------------------------------------------------------<br>
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" <br>
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" <br>
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" <br>
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"<br>
<br>
begin<br>
<br>
f=addfile("/mnt/geog/ml382/McGill_Project/ReanalysisV2/uwnd_krakatoa.nc", "r") <br>
<br>
g=addfile("/mnt/geog/ml382/McGill_Project/ReanalysisV2/vwnd_krakatoa.nc", "r")
<br>
<br>
<br>
latS = -70.<br>
latN = 50. <br>
lonL = 0.<br>
lonR = 150.<br>
<br>
u = f->uwnd(:,0,:,:)<br>
v = g->vwnd(:,0,:,:)<br>
<br>
lat = f->lat<br>
lon = f->lon<br>
time = f->time<br>
<br>
speed= new(dimsizes(u),float) <br>
<br>
do gg = 0,dimsizes(time)-1 <br>
<br>
speed(gg,:,:) = sqrt(u(gg,:,:)^2+v(gg,:,:)^2)<br>
<br>
speed!0 = "time"<br>
speed!1 = "lat"<br>
speed!2 = "lon"<br>
speed&time= time <br>
speed&lat = lat<br>
speed&lon = lon<br>
speed@long_name = "Wind Speed"<br>
speed@units = "m/s"<br>
<br>
<br>
wks = gsn_open_wks("X11","Krakatoa_Animation_"+time(gg)+"") ; specifies a plot<br>
plot = new (dimsizes(time),"graphic")<br>
plot1= new (dimsizes(time),"graphic")<br>
plot2= new (dimsizes(time),"graphic")<br>
x= new (dimsizes(time),"float")<br>
y= new (dimsizes(time),"float")<br>
;---Create plot<br>
<br>
res = True ; plot mods desired<br>
<br>
res@cnFillOn = True ; turn on color for contours<br>
res@cnLinesOn = False ; turn off contour lines<br>
res@cnLineLabelsOn = False ; turn off contour line labels<br>
res@gsnScalarContour = True ; contours desired<br>
res@gsnDraw = False ; do not draw the plot<br>
res@gsnFrame = False <br>
<br>
<br>
res@vcRefMagnitudeF = 2.0 ; define vector ref mag<br>
res@vcRefLengthF = 0.008 ; define length of vec ref<br>
res@vcRefAnnoOrthogonalPosF = -1.0 ; move ref vector<br>
res@vcRefAnnoArrowLineColor = "black" ; change ref vector color<br>
res@vcRefAnnoArrowUseVecColor = False ; don't use vec color for ref<br>
<br>
res@vcGlyphStyle = "CurlyVector" ; turn on curley vectors<br>
res@vcLineArrowColor = "black" ; change vector color<br>
res@vcLineArrowThicknessF = 2.0 ; change vector thickness<br>
res@vcVectorDrawOrder = "PostDraw" ; draw vectors last<br>
res@vcMinDistanceF = 0.02<br>
<br>
res@gsnLeftString = ""<br>
res@gsnMainString = "" <br>
res@gsnRightString = ""<br>
<br>
res@mpMinLonF = lonL ; select a subregion<br>
res@mpMaxLonF = lonR<br>
res@mpMinLatF = latS<br>
res@mpMaxLatF = latN<br>
<br>
<br>
pres = True<br>
pres@mpFillOn = False<br>
pres@cnFillOn = True ; color on<br>
pres@cnLinesOn = False ; turn off contour lines<br>
pres@gsnScalarContour = True ; vectors over contours<br>
pres@gsnSpreadColors = True ; use full colormap<br>
pres@gsnAddCyclic = False<br>
pres@gsnDraw = False ; do not draw the plot<br>
pres@gsnFrame = False <br>
pres@lbLabelBarOn = False<br>
pres@gsnMaximize = True<br>
<br>
pres@mpMinLonF = lonL ; select a subregion<br>
pres@mpMaxLonF = lonR<br>
pres@mpMinLatF = latS<br>
pres@mpMaxLatF = latN<br>
<br>
<br>
pres@gsnLeftString = ""<br>
pres@gsnMainString = "" <br>
pres@gsnRightString = ""<br>
<br>
<br>
pres@cnLevelSelectionMode= "ManualLevels" ; manual levels<br>
pres@cnMinLevelValF = -100 ; min level<br>
pres@cnMaxLevelValF = 120 ; max level<br>
pres@cnLevelSpacingF = 10 ; contour spacing<br>
<br>
<br>
mres = True <br>
mres@gsMarkerIndex = 3 ; polymarker style<br>
mres@gsMarkerSizeF = 20. ; polymarker size<br>
mres@gsMarkerColor = "red" <br>
<br>
mpres = True ; plot mods desired<br>
mpres@xyMarkLineModes = "Markers" ; choose which have markers<br>
mpres@xyMarkers = 16 ; choose type of marker <br>
mpres@xyMarkerColor = "red" ; Marker color<br>
mpres@xyMarkerSizeF = 0.01 ; Marker size (default 0.01)<br>
<br>
<br>
;Ship track data<br>
<br>
ship = "/mnt/geog/ml382/McGill_Project/ReanalysisV2/Krakatoa_ID.txt"<br>
data = asciiread(ship,-1,"string")<br>
year = stringtointeger(str_get_cols(data,1,5))<br>
month = stringtointeger(str_get_cols(data,8,9))<br>
day = stringtointeger(str_get_cols(data,11,13))<br>
hour = stringtointeger(str_get_cols(data,15,20))<br>
slat = stringtointeger(str_get_cols(data,22,28))<br>
slon = stringtointeger(str_get_cols(data,31,37))<br>
<br>
<br>
k=0<br>
<br>
<br>
do j=0, 4<br>
jj=j+1881<br>
do i=0, 11<br>
do m=0, 30<br>
n = 0<br>
do nn=0, 7304<br>
<br>
data_index = ind((year(k) .eq. jj) .and. (month(k) .eq. i) .and. (day(k) .eq. m) .and. (hour(k) .eq. n))<br>
<br>
<br>
if(.not. any(ismissing(data_index))) then<br>
x(k)=slon(data_index)<br>
y(k)=slat(data_index)<br>
<br>
print(x)<br>
print(y)<br>
<br>
end if<br>
<br>
polyres = True ; poly marker mods desired <br>
polyres@gsMarkerIndex = 16 ; choose circle as polymarker<br>
polyres@gsMarkerSizeF = 7.0 ; select size to avoid streaking<br>
polyres@gsMarkerColor = "red" ; choose color<br>
<br>
<br>
pres@gsnLeftString = "Krakatoa: Winds and Shipping Tracks"<br>
plot(gg) = gsn_csm_contour_map(wks,speed(gg,:,:),pres)<br>
plot1(gg)= gsn_csm_vector(wks,u(gg,:,:),v(gg,:,:),res)<br>
<br>
<br>
overlay(plot(gg),plot1(gg))<br>
<br>
plot2(gg) = gsn_add_polymarker(wks,plot(gg),x(k),y(k),polyres) ; draw polymarkers<br>
<br>
<br>
draw(plot(gg))<br>
frame(wks)<br>
<br>
k=k+1<br>
n=nn+6 <br>
<br>
end do<br>
end do<br>
end do<br>
end do<br>
end do<br>
<br>
end<br>
<br>
</div>
</body>
</html>