data_var='prate' year=1992 year_max=2008 *Loop over each year while ( year < year_max) * Set filename for the new input file data_fname='prate.sfc.gauss.'year'.nc' * reinit to be safe 'reinit' say 'Opening file with: sdfopen 'data_fname 'sdfopen 'data_fname * Find the X and Y extents 'q dims' rec=sublin(result,2) Imax=subwrd(rec,13) say 'Imax 'Imax rec=sublin(result,3) Jmax=subwrd(rec,13) say 'Jmax 'Jmax * Find the T extent 'q file 1' rec=sublin(result,5) Tmax=subwrd(rec,12) say 'Tmax 'Tmax 'set gxout shaded' 'd 'data_var t=1 * Loop over all times in the file while ( t <= Tmax ) * Set name of the new output file out_fname='prate_ascii_'year'_'t'.csv' * Write headers for the output file rc = write(out_fname,'yyyymmdd,latval,lonval,prate') * Grab date info to make a nicely formatted date 'set t 't 'q time' rec=sublin(result,1) bigdate=subwrd(rec,3) yyyy=substr(bigdate,9,4) mmm=substr(bigdate,6,3) dd=substr(bigdate,4,2) if(mmm = 'JAN') mm='01' endif if(mmm = 'FEB') mm='02' endif if(mmm = 'MAR') mm='03' endif if(mmm = 'APR') mm='04' endif if(mmm = 'MAY') mm='05' endif if(mmm = 'JUN') mm='06' endif if(mmm = 'JUL') mm='07' endif if(mmm = 'AUG') mm='08' endif if(mmm = 'SEP') mm='09' endif if(mmm = 'OCT') mm='10' endif if(mmm = 'NOV') mm='11' endif if(mmm = 'DEC') mm='12' endif date_string=''yyyy''mm''dd i=1 * Imax=1 * Imax=162 * Jmax=1 while ( i <= Imax ) j=1 'set x 'i while ( j <= Jmax ) 'q gr2w 'i' 'j say 't='t' q gr2w 'i' 'j rec = sublin(result,1) lonv = subwrd(rec,3) latv = subwrd(rec,6) 'set y 'j *DEBUGGING if(i = 161) say 'd 'data_var endif 'd 'data_var var = subwrd(result,4) *UNCOMMENT FOR DEBUGGING say ''i' 'j' 'lonv' 'latv' 'var lonval = math_format('%6.3f',lonv) latval = math_format('%6.3f',latv) var = math_format('%16.13f',var) if(i = 161) if(j > 60) *MORE DEBUGGING say 'rc = write('out_fname','date_string','latval','lonval','var')' endif endif rc = write(out_fname,''date_string','latval','lonval','var'') if(i = 161) if(j>60) *MORE DEBUGGING say 'j='j'+1' endif endif j=j+1 endwhile i=i+1 endwhile *MORE DEBUGGING say 'incrementing t='t'+1' t=t+1 rc = close(out_fname) endwhile say 'close 1' 'close 1' year=year+1 year=year_max endwhile