<div dir="ltr"><div> Makng a separate case for each 'duration' is  VERY cumbersome.</div><div><br></div><div>You must come up with a method where (i) a 'switch' is set; (ii) as long as the switch is set, accumulate the 'tx'  values and a counter 'txknt'; (iii) when switch is turned off; average the accumulated values; (iv) reset counter<br></div><div><br></div><div> See attached script.</div><div><br></div><div><b>%></b> ncl YooRimJung.ncl</div><div><br></div><div>--</div><div>output</div><div>---</div><div> yyyy  m  d  tx  o  du  avg<br></div><div>1981 06 29 26 0 00 -99.00<br>1981 06 30 33 1 <b>03  34.00</b><br>1981 07 01 34 0 00 -99.00<br>1981 07 02 35 0 00 -99.00<br>1981 07 03 30 0 00 -99.00<br>1981 07 04 33 1 <b>05  33.00</b><br>1981 07 05 33 0 00 -99.00<br>1981 07 06 33 0 00 -99.00<br>1981 07 07 33 0 00 -99.00<br>1981 07 08 33 0 00 -99.00<br>1981 07 09 28 0 00 -99.00<br>1981 07 10 70 <b>1 02  80.00</b><br>1981 07 11 90 0 00 -99.00</div><div><br></div><div><br></div><div><br></div><div><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Aug 21, 2019 at 3:12 AM YooRim Jung via ncl-talk <<a href="mailto:ncl-talk@ucar.edu">ncl-talk@ucar.edu</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hello,<div>I am attempting to calculate heatwave(Tmax >= 33C) events with different durations  (any consecutive days:    >=2 days, 3days, ... 30days).<br></div><div>I am trying to make a code using the daily Tmax data (Ascii) as follows and I'd like to write output in the following format. <br></div><div>But, my source code is very limited and too complicated.</div><div>Could you let me know the best way to make a simple code?<br></div><div>Thank you.</div><div><br></div><div><br></div><div>INPUT Data sample</div><div>===========================================================</div><div>Station1</div><div>Year Month  Day  Tmax       <br></div><div>1981    6       29      26             </div><div>1981    6       30      33             </div><div>1981    7         1      34            </div><div>1981    7         2      35           </div><div>1981    7         3      30              </div><div>1981    7         4      33              </div><div>1981    7         5      33              </div><div>1981    7         6      33              </div><div>1981    7         7      33            </div><div>1981    7         8      33           <br></div><div>1981    7         9      28       </div><div>.........</div><div>Station2</div><div>.........</div><div><br></div><div>OUTPUT Data sample       <br></div><div><div>===========================================================</div><div>Station1</div></div><div><div>Year Month  Day  Tmax         Onset    Duration    AvgTmax<br></div><div>1981    6       29      26                0              0                0</div><div>1981    6       30      33                1              3           (33+34+35)/3</div><div>1981    7         1      34                0              0                0</div><div>1981    7         2      35                0              0                0</div><div>1981    7         3      30                0              0                0</div><div>1981    7         4      33                1              5          (33+33+33+33+33)/5</div><div>1981    7         5      33                0              0                0     </div><div>1981    7         6      33                0              0                0 </div><div>1981    7         7      33                0              0                0</div><div>1981    7         8      33                0              0                0 <br></div><div>1981    7         9      28                0              0                0</div></div><div><div>.........</div><div>Station2</div><div>.........</div><br class="gmail-m_4148899990885092348gmail-Apple-interchange-newline"></div><div>NCL Code<br></div><div>===========================================================</div><div>nd = (/31,28,31,30,31,30,31,31,30,31,30,31/)</div><div><br></div><div>jrec = -1</div><div>do year    = 1981, 1982<br></div><div>do month = 1, 12</div><div>do day     = 0, nd(month-1)</div><div>      jrec = jrec + 1</div><div>do stn      = 0, ns-1           ; ns : # of observation station</div><div><br></div><div>     ;;;; duration >2 days</div><div>           if(tmax(stn,jrec).ge.33 .and. tmax(stn,jrec+1).ge.33) then</div><div>                  hyy(stn,0) = year                                                            ; heatwave onset day (year)</div><div>                  hmm(stn,0) = month                                                      ; heatwave onset day  (month)</div><div>                  hdd(stn,0) = day                                                            ; heatwave onset day   (day)<br></div><div>                  hindex(stn,0) = 1                                                           ; if hw onset day, marked as 1</div><div>                  htx(stn,0)  = (tmax(stn,jrec)+tmax(stn,jrec+1)) / hdr      ; tmax average with duration 2dys<br></div><div>           end if</div><div>    </div><div><div>    ;;;; duration >3 days</div><div>           if(tmax(stn,jrec).ge.33 .and. tmax(stn,jrec+1).ge.33 .and. tmax(stn,jrec+2).ge.33 ) then</div><div><div>                  hyy(stn,1) = year                                                            ; heatwave onset day (year)</div><div>                  hmm(stn,1) = month                                                      ; heatwave onset day  (month)</div><div>                  hdd(stn,1) = day                                                            ; heatwave onset day   (day)<br></div></div><div>                  hindex(stn,1) = 1                                                           ; if hw onset day, marked as 1  <br></div><div>                  htx(stn,1)  = (tmax(stn,jrec)+tmax(stn,jrec+1)+tmax(stn,jrec+2)) / hdr      ; tmax average with duration 3dys<br></div></div><div>            end if</div><div><br></div><div><div> ;;;; duration >4 days</div><div>           if(tmax(stn,jrec).ge.33 .and. tmax(stn,jrec+1).ge.33 and. tmax(stn,jrec+2).ge.33 and. tmax(stn,jrec+3).ge.33) then</div><div><div>                  hyy(stn,2) = year                                                            ; heatwave onset day (year)</div><div>                  hmm(stn,2) = month                                                      ; heatwave onset day  (month)</div><div>                  hdd(stn,2) = day                                                            ; heatwave onset day   (day)<br></div></div><div>                  hindex(stn,2) = 1                                                           ; if hw onset day, marked as 1  <br></div><div>                  htx(stn,2)  = (tmax(stn,jrec)+tmax(stn,jrec+1)+tmax(stn,jrec+2)+tmax(stn,jrec+3)) / hdr      ; tmax average with duration 4dys<br></div></div><div>           end if  <br></div><div><br></div><div>;;;; duration >30 days  <br></div><div>           .........<br></div><div><br></div><div>end do</div><div>end do</div><div>end do</div><div>end do</div><div><br></div><div><br></div><div>Sincerely,</div><div>YR<br></div><div><br></div><div><br></div><div><br></div></div>
_______________________________________________<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></blockquote></div>