<div dir="ltr"><div class="gmail_default" style="font-size:small">Hi Melissa,</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">Sorry about the delay. I've got a lot of emails to deal with.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">I think that you can get rid of many of your do loops, and that really, you should only need to loop across time, and then add all the markers at one point to each time step.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">Right now, it looks like you are creating one plot at a time, and only adding one marker to each plot. Is this what you want? </div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">I'm thinking your code should look something more like this:</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace">data_indexes = ind(year .ge. 1881 .and. year .le. 1885 .and.\</font></div><div class="gmail_default"><font face="monospace, monospace"> month .ge. 8 .and. month .le. 19 .and.\</font></div><div class="gmail_default"><font face="monospace, monospace"> day .ge. 0 .and. day .le. 30 .and.\</font></div><div class="gmail_default"><font face="monospace, monospace"> hour .ge. 0 .and. hour .le. 29)<span class="Apple-tab-span" style="white-space:pre">        </span></font></div><div class="gmail_default"><font face="monospace, monospace"><br></font></div><div class="gmail_default"><font face="monospace, monospace">lons = slon(data_indexes)</font></div><div class="gmail_default"><font face="monospace, monospace">lats = slat(data_indexes)</font></div><div class="gmail_default"><font face="monospace, monospace"><br></font></div><div class="gmail_default"><font face="monospace, monospace">do gg = 0,dimsizes(time)-1</font></div><div class="gmail_default"><font face="monospace, monospace"> plot(gg) = gsn_csm_map_ce(wks,mapres)</font></div><div class="gmail_default"><font face="monospace, monospace"> plot1(gg)= gsn_csm_vector(wks,u(gg,:,:),v(gg,:,:),res)</font></div><div class="gmail_default"><font face="monospace, monospace"> overlay(plot(gg),plot1(gg))</font></div><div class="gmail_default"><font face="monospace, monospace"> plot2(gg) = gsn_add_polymarker(wks,plot(gg),lons,lats,polyres)</font></div><div class="gmail_default"><font face="monospace, monospace">end do</font></div><div class="gmail_default" style="font-size:small"><br></div></div><div class="gmail_default" style="font-size:small">Note that I don't think the "data_indexes" line is quite correct, because I don't understand why your months would go from 8 to 19. I would have to see your various year, month, etc arrays to better understand what time range you are trying to select.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">But, hopefully you understand what the above code is doing, and you can fix it as necessary.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">--Mary</div><div class="gmail_default" style="font-size:small"><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 3, 2015 at 9:34 AM, Melissa Lazenby <span dir="ltr"><<a href="mailto:M.Lazenby@sussex.ac.uk" target="_blank">M.Lazenby@sussex.ac.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>
<div style="direction:ltr;font-family:Tahoma;color:#000000;font-size:10pt">Hi Mary<br>
<br>
Sorry I was not specific enough.<br>
The main problem is with the loops to create the conditions when reading in the text file.<br>
Below is a snippet of the code that isn't running how I would like it too.<br>
<br>
yrs=4<br>
mons=12<br>
days=31 <br>
hrs=23<br>
<br>
do j=0, yrs-1<br>
jj=j+1881<br>
do i=0, mons-1<br>
ii=i+8<br>
do m=0, days-1<br>
do n = 0, hrs+6<br>
<br>
data_index = ind((year .eq. jj) .and. (month .eq. ii) .and. (day .eq. m) .and. (hour .eq. n))
<br>
<br>
if(.not. any(ismissing(data_index))) then<br>
x=slon(data_index)<br>
y=slat(data_index)<br>
<br>
end if<br>
<br>
do gg = 0,dimsizes(time)-1 <br>
<br>
plot(gg) = gsn_csm_map_ce(wks,mapres)<span class=""><br>
plot1(gg)= gsn_csm_vector(wks,u(gg,:,:),v(gg,:,:),res)<br>
<br>
overlay(plot(gg),plot1(gg))<br>
<br></span>
plot2(gg) = gsn_add_polymarker(wks,plot(gg),x,y,polyres) <br><span class="">
<br>
end do<br>
end do<br>
end do<br>
end do<br>
end do<br>
<br></span>
When I put actual values in for jj, ii, m and n, the code runs perfectly and plots just those shipping tracks I want according to the conditional statement. But because there is a lot of data, I want to create loops that go through the years, months, days and
hours (only every 6 hours) and the output is not looping through the different winds values and different shipping track data. It either gets the wind to change and the ship tracks to stay the same or vise versa.<br>
<br>
I do not have much experience with how to write do loops and I think my syntax is not correct so if there are any examples to help me or your advice would be great.<span class=""><br>
<br>
Many thanks!<br>
<br>
Kindest Regards<br>
Melissa<br>
<br>
</span><div style="font-family:Times New Roman;color:#000000;font-size:16px">
<hr>
<div style="direction:ltr"><font face="Tahoma" color="#000000" size="2"><b>From:</b> Mary Haley [<a href="mailto:haley@ucar.edu" target="_blank">haley@ucar.edu</a>]<br>
<b>Sent:</b> 03 August 2015 16:09<br>
<b>To:</b> Melissa Lazenby<br>
<b>Cc:</b> <a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a><br>
<b>Subject:</b> Re: [ncl-talk] Winds overlaid with shipping track data<br>
</font><br>
</div><div><div class="h5">
<div></div>
<div>
<div dir="ltr">
<div class="gmail_default" style="font-size:small">Melissa,</div>
<div class="gmail_default" style="font-size:small"><br>
</div>
<div class="gmail_default" style="font-size:small">Could you be more specific than "it's not working correctly?" It's hard for us to debug a problem when we don't know where to look. </div>
<div class="gmail_default" style="font-size:small"><br>
</div>
<div class="gmail_default" style="font-size:small">It's also helpful to include a sample image with an explanation of what's wrong with it, or an error message.</div>
<div class="gmail_default" style="font-size:small"><br>
</div>
<div class="gmail_default" style="font-size:small">--Mary</div>
<div class="gmail_default" style="font-size:small"><br>
</div>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Fri, Jul 31, 2015 at 10:28 AM, Melissa Lazenby <span dir="ltr">
<<a href="mailto:M.Lazenby@sussex.ac.uk" target="_blank">M.Lazenby@sussex.ac.uk</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div>
<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/<a href="http://uwnd_krakatoa.nc" target="_blank">uwnd_krakatoa.nc</a>", "r")
<br>
<br>
g=addfile("/mnt/geog/ml382/McGill_Project/ReanalysisV2/<a href="http://vwnd_krakatoa.nc" target="_blank">vwnd_krakatoa.nc</a>", "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>
</div>
<br>
_______________________________________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu" target="_blank">ncl-talk@ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
<br>
</blockquote>
</div>
<br>
</div>
</div>
</div></div></div>
</div>
</div>
</blockquote></div><br></div>