<html><body><div style="color:#000; background-color:#fff; font-family:garamond, new york, times, serif;font-size:14pt"><div>Hi,</div><div><br></div><div class="yui_3_13_0_ym1_6_1392287372419_29" style="color: rgb(0, 0, 0); font-size: 18.6667px; font-family: garamond,new york,times,serif; background-color: transparent; font-style: normal;">It's my deepest request to whosoever working to write 4-dimensional netcdf data using grads since sdfwrite is unable to generate 4-D netcdf data. My global netcdf data is in 4-D format with each yearly file has 12 time and 15 vertical points. I am trying to save errenous data from these files into netcdf format in 4-dimensions. I have tried many methods of looping in z and t scales. Although loops in z and t scales are running properly as grads displays sorted data for each time and each layer, the output file only saves data in netcdf format for final time and final layer which is 2-dimensional data. It is clear that
 the sdfwrite command does not allow one to write out more than one variable to a file (source: grads documentation on sdfwrite) so the sdfwrite generates output for one time and one layer only.<br></div><div class="yui_3_13_0_ym1_6_1392287372419_29" style="color: rgb(0, 0, 0); font-size: 18.6667px; font-family: garamond,new york,times,serif; background-color: transparent; font-style: normal;"><br></div><div class="yui_3_13_0_ym1_6_1392287372419_29" style="color: rgb(0, 0, 0); font-size: 18.6667px; font-family: garamond,new york,times,serif; background-color: transparent; font-style: normal;">However, can someone tell me how to write a loop in grads to generate multiple netcdf files using sdfwrite command for each single time and each layer from my 4-D netcdf data? Once number of netcdf files are generated with data for different time and layers, I hope sdfwrite allows to <span id="misspell-15" class="">concatenate</span> all files for multiple layers
 first and then for long time series.</div><div class="yui_3_13_0_ym1_6_1392287372419_29" style="color: rgb(0, 0, 0); font-size: 18.6667px; font-family: garamond,new york,times,serif; background-color: transparent; font-style: normal;"><br></div><div class="yui_3_13_0_ym1_6_1392287372419_29" style="color: rgb(0, 0, 0); font-size: 18.6667px; font-family: garamond,new york,times,serif; background-color: transparent; font-style: normal;">Here, I have tried a looping to produce multiple files for each layer and each time but it hasn't worked.</div><div class="yui_3_13_0_ym1_6_1392287372419_29" style="color: rgb(0, 0, 0); font-size: 18.6667px; font-family: garamond,new york,times,serif; background-color: transparent; font-style: normal;">_____________________________________________________________________________________<br></div><div class="yui_3_13_0_ym1_6_1392287372419_29" style="color: rgb(0, 0, 0); font-size: 18.6667px; font-family: garamond,new
 york,times,serif; background-color: transparent; font-style: normal;">'set lon 0 360'<br>'set lat -90 90'<br></div><div class="yui_3_13_0_ym1_6_1392287372419_29" style="color: rgb(0, 0, 0); font-size: 18.6667px; font-family: garamond,new york,times,serif; background-color: transparent; font-style: normal;"><br></div><div class="yui_3_13_0_ym1_6_1392287372419_29" style="color: rgb(0, 0, 0); font-size: 18.6667px; font-family: garamond,new york,times,serif; background-color: transparent; font-style: normal;">'set sdfwrite -4d flt -nc4 data_'z'_'t'.nc'<br>'sdfwrite var'<br><br>t=1<br>&nbsp;while(t&lt;=12)<br>&nbsp; 'set t 't<br><br>&nbsp;&nbsp; z=1</div><div class="yui_3_13_0_ym1_6_1392287372419_29" style="color: rgb(0, 0, 0); font-size: 18.6667px; font-family: garamond,new york,times,serif; background-color: transparent; font-style: normal;">&nbsp;&nbsp;&nbsp; while(z&lt;=15)<br>&nbsp;&nbsp;&nbsp;&nbsp; 'set z 'z</div><div
 class="yui_3_13_0_ym1_6_1392287372419_29" style="color: rgb(0, 0, 0); font-size: 18.6667px; font-family: garamond,new york,times,serif; background-color: transparent; font-style: normal;"><br></div><div class="yui_3_13_0_ym1_6_1392287372419_29" style="color: rgb(0, 0, 0); font-size: 18.6667px; font-family: garamond,new york,times,serif; background-color: transparent; font-style: normal;"><span style="font-style: italic;">#&nbsp; rec=read(filename.nc)</span></div><div class="yui_3_13_0_ym1_6_1392287372419_29" style="color: rgb(0, 0, 0); font-size: 18.6667px; font-family: garamond,new york,times,serif; background-color: transparent; font-style: normal;"><span style="font-style: italic;"><span># IO = sublin(rec,1)</span></span><i><br></i></div><div class="yui_3_13_0_ym1_6_1392287372419_29" style="color: rgb(0, 0, 0); font-size: 18.6667px; font-family: garamond,new york,times,serif; background-color: transparent; font-style: italic;"><i># if (IO = 0)
</i><br></div><div class="yui_3_13_0_ym1_6_1392287372419_29" style="color: rgb(0, 0, 0); font-size: 18.6667px; font-family: garamond,new york,times,serif; background-color: transparent; font-style: italic;">#<i> a = subwrd(rec,2) </i><br></div><div class="yui_3_13_0_ym1_6_1392287372419_29" style="color: rgb(0, 0, 0); font-size: 18.6667px; font-family: garamond,new york,times,serif; background-color: transparent; font-style: italic;"># <i>endif </i><i><br></i></div><div class="yui_3_13_0_ym1_6_1392287372419_29" style="color: rgb(0, 0, 0); font-size: 18.6667px; font-family: garamond,new york,times,serif; background-color: transparent; font-style: italic;"><i># 'sdfopen 'a'' <br></i></div><div class="yui_3_13_0_ym1_6_1392287372419_29" style="color: rgb(0, 0, 0); font-size: 18.6667px; font-family: garamond,new york,times,serif; background-color: transparent; font-style: italic;"># <i>say '' <br></i></div><div class="yui_3_13_0_ym1_6_1392287372419_29"
 style="color: rgb(0, 0, 0); font-size: 18.6667px; font-family: garamond,new york,times,serif; background-color: transparent; font-style: italic;"># <i>say ' Filename: 'a'' <br></i></div><div class="yui_3_13_0_ym1_6_1392287372419_29" style="color: rgb(0, 0, 0); font-size: 18.6667px; font-family: garamond,new york,times,serif; background-color: transparent; font-style: italic;"># <i>say ' File no: 'z'_'t''</i></div><div class="yui_3_13_0_ym1_6_1392287372419_29" style="color: rgb(0, 0, 0); font-size: 18.6667px; font-family: garamond,new york,times,serif; background-color: transparent; font-style: italic;"><i><br></i></div><div class="yui_3_13_0_ym1_6_1392287372419_29" style="color: rgb(0, 0, 0); font-size: 18.6667px; font-family: garamond,new york,times,serif; background-color: transparent; font-style: normal;"><br></div><div class="yui_3_13_0_ym1_6_1392287372419_29" style="color: rgb(0, 0, 0); font-size: 18.6667px; font-family: garamond,new
 york,times,serif; background-color: transparent; font-style: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'define var = var'</div><div class="yui_3_13_0_ym1_6_1392287372419_29" style="color: rgb(0, 0, 0); font-size: 18.6667px; font-family: garamond,new york,times,serif; background-color: transparent; font-style: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 'd var'</div><div class="yui_3_13_0_ym1_6_1392287372419_29" style="color: rgb(0, 0, 0); font-size: 18.6667px; font-family: garamond,new york,times,serif; background-color: transparent; font-style: normal;">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #'set sdfwrite -4d flt -nc4 data-sort_'z'_'t'.nc'<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #'sdfwrite var'</div><div class="yui_3_13_0_ym1_6_1392287372419_29" style="color: rgb(0, 0, 0); font-size: 18.6667px; font-family: garamond,new york,times,serif; background-color:
 transparent; font-style: normal;"><br></div><div class="yui_3_13_0_ym1_6_1392287372419_29" style="color: rgb(0, 0, 0); font-size: 18.6667px; font-family: garamond,new york,times,serif; background-color: transparent; font-style: normal;">&nbsp;&nbsp;&nbsp; z=z+1<br>&nbsp;&nbsp; endwhile<br>&nbsp;t=t+1<br>endwhile<br><br></div><div class="yui_3_13_0_ym1_6_1392287372419_29" style="color: rgb(0, 0, 0); font-size: 18.6667px; font-family: garamond,new york,times,serif; background-color: transparent; font-style: normal;">Thank you for your help and support here.</div><div class="yui_3_13_0_ym1_6_1392287372419_29" style="color: rgb(0, 0, 0); font-size: 18.6667px; font-family: garamond,new york,times,serif; background-color: transparent; font-style: normal;">Regards</div><div style="color: rgb(0, 0, 0); font-size: 18.6667px; font-family: garamond,new york,times,serif; background-color: transparent; font-style: normal;">Pankaj<br></div></div></body></html>