<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-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>