'reinit'
'sdfopen /net/stg/netcdf/isabel_ras.nc'
*
*  find Imax, Jmax
*
'q dims'
rec=sublin(result,2)
Imax=subwrd(rec,13)
say 'Imax 'Imax
rec=sublin(result,3)
Jmax=subwrd(rec,13)
say 'Jmax 'Jmax
*
*  define scaling environment by displaying any variable (otherwise an error
*  results...)
*
'set gxout shaded'
'd ps'
*
*  open output file and print header...
*
rc = write('test_gr2w.txt','i j  lonval latval  var')
i=1
while ( i <= Imax )
  j=1
  while ( j <= Jmax )
    'q gr2w 'i' 'j
    rec = sublin(result,1)
    lonv = subwrd(rec,3)
    latv = subwrd(rec,6)
    'set x 'i
    'set y 'j
    'd ps'
    var = subwrd(result,4)
    say ''i' 'j' 'lonv' 'latv' 'var
    lonval = math_format('%6.3f',lonv)
    latval = math_format('%6.3f',latv)
    rc = write('test_gr2w.txt',''i' 'j' 'lonval' 'latval' 'var'')
    j=j+1
  endwhile
  i=i+1
endwhile
rc = close('test_gr2w.txt')
