<div dir="ltr">Hi all<br><br>I have 3 hourly data from 1948 to 2100 and I want to calculate multi-monthly in 7 sub-regions. The script is attachment as follows. It cannot work at all. I hope anyone can help me to modify it. Thank you very much.<br>
<br>Best,<br><br>Xiaoli<br><br><br>function subset(args)
<br> <br>mods=&quot;MPI-ESM-LR &quot;
<br>vars=&quot;prec tas&quot;
<br>monstrs=&quot;JAN FEB MAR APR MAY JUN JUL AUG SEP OCT NOV DEC&quot; 
<br>mds=&quot;31 28 31 30 31 30 31 31 30 31 30 31&quot;
<br> <br>lat1=17.5; lat2=54.5
<br>lon1=72.5; lon2=135.5
<br> <br>&#39;open /home/xiaoliy/mask_0.5_8region.ctl&#39;
<br>&#39;define msk1=re(data, 63, linear, 72.5, 1, 38, linear, 17.5, 1, vt, 0.2, 0.6)&#39;
<br> <br>&#39;close 1&#39;
<br>&#39;set gxout grfill&#39;
<br> <br> mod=1
<br> while (mod&lt;=1)
<br>     
<br>     model=subwrd(mods, mod)
<br>     say model
<br>     
<br>     v=1
<br>     while (v&lt;=1)
<br>    
<br>        var=subwrd(vars, v)
<br>        say var
<br>    
<br>        &#39;!mkdir -p /home/xiaoliy/&#39;model&#39;/&#39;var
<br> <br>             y1=1948
<br>             y2=2100
<br>            
<br>             y=1948
<br>              while (y&lt;=y2)
<br> <br>    
<br>          
<br>            &#39;open /home/xiaoliy/&#39;model&#39;/3hourly/&#39;var&#39;_&#39;y&#39;-&#39;y&#39;.ctl&#39;
<br>      
<br>             dout=&quot;/home/xiaoliy/&quot;model&quot;/china/&quot;var&quot;/&quot;var&quot;_&quot;model&quot;_multi_monthly_&quot;y&quot;-&quot;y&quot;.dat&quot;
<br>             &#39;!/bin/rm -f &#39;dout
<br>        
<br>            &#39;set gxout fwrite&#39;
<br>            
<br>             &#39;set lat &#39;lat1&#39; &#39;lat2
<br>             &#39;set lon &#39;lon1&#39; &#39;lon2 
<br>     
<br>             &#39;set t 00z1jan1948 21z1dec2100&#39;
<br>             
<br>               m=1
<br>               while (m&lt;=12)
<br>                 
<br>                mmm=subwrd(monstrs, m)
<br>                md=subwrd(mds, m)
<br>                
<br>                if (m=2&amp;math_mod(y, 4)=0)
<br>                  
<br>                  mmd=29
<br>                endif
<br>                
<br>               
<br> <br> <br>                
<br>                 val=y&quot; &quot;mm
<br>                                 
<br>                time1=&quot;01&quot;%mmm%y
<br>                time2=&quot;31&quot;%mmm%y
<br>                                
<br>                &#39;set time 00z1jan1948&#39;
<br>               
<br>                
<br>                 d=1
<br>                    while (d&lt;=d2)
<br>                    
<br>               
<br>                      r=1  
<br>                       while (r&lt;=7)
<br>                        
<br>                         &#39;define a=ave(data, t=8*d-7, t=8*d)&#39; 
<br>                                                    
<br>                       
<br>                         &#39;d ave(aave(magcm/skout(a, (msk1-&#39;r-0.5&#39;)*(&#39;r+0.5&#39;-msk1)), g), time=jan&#39;y&#39;, time=dec&#39;y&#39;)&#39;
<br>                        
<br>                          value=sublin(result,2)
<br>                          pfiles=subwrd(value, 4)
<br>                          val=val&quot; &quot;pfiles
<br> <br>                     r=r+1
<br>                   endwhile<br><br>              <br>*                say &quot;Extracting from step &quot;d&quot; to &quot;d2<br>                  <br>                 d=d+1
<br>                 endwhile
<br>                 
<br> 
<br>               say val
<br>               ret=write(dout, val, append)
<br>               ret=close(dout)
<br>                
<br>             m=m+1
<br>           endwhile
<br> <br>          y=y+1
<br>         endwhile
<br>            
<br>       v=v+1
<br>       endwhile
<br>       &#39;close 1&#39;
<br>   
<br>   mod=mod+1
<br>   endwhile     
<br> <br>    
<br>       
<br> 
<br> <br> <br>&#39;quit&#39;          
<br> <br>return<br> <br></div>