<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META content="text/html; charset=us-ascii" http-equiv=Content-Type>
<META name=GENERATOR content="MSHTML 8.00.6001.19019"></HEAD>
<BODY>
<DIV dir=ltr align=left><SPAN class=890421911-04032011><FONT color=#0000ff 
size=2 face=Arial>Arlindo,</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=890421911-04032011><FONT color=#0000ff 
size=2 face=Arial></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=890421911-04032011><FONT color=#0000ff 
size=2 face=Arial>great, thanks!</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=890421911-04032011><FONT color=#0000ff 
size=2 face=Arial></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=890421911-04032011><FONT color=#0000ff 
size=2 face=Arial>Would it not be more intuitive to extend the scope of lats4d 
to accept</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=890421911-04032011><FONT color=#0000ff 
size=2 face=Arial>all currently user defined variables to be writen out, similar 
to&nbsp; fwrite?</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=890421911-04032011><FONT color=#0000ff 
size=2 face=Arial></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=890421911-04032011><FONT color=#0000ff 
size=2 face=Arial>User defined variables may be plotted or written out via 
fwrite according to </FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=890421911-04032011><FONT color=#0000ff 
size=2 face=Arial>current dimension settings. </FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=890421911-04032011><FONT color=#0000ff 
size=2 face=Arial></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=890421911-04032011><FONT color=#0000ff 
size=2 face=Arial>The long way home seems to be to write out with fwrite first, 
build a ctl file</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=890421911-04032011><FONT color=#0000ff 
size=2 face=Arial>and then translate the binary file to grib with lats4d. 
</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=890421911-04032011><FONT color=#0000ff 
size=2 face=Arial></FONT></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=890421911-04032011><FONT color=#0000ff 
size=2 face=Arial>Thanks for your help,</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=890421911-04032011><FONT color=#0000ff 
size=2 face=Arial>Bernd.</FONT></SPAN></DIV>
<DIV dir=ltr align=left><SPAN class=890421911-04032011></SPAN>&nbsp;</DIV>
<DIV dir=ltr align=left><SPAN class=890421911-04032011><FONT color=#0000ff 
size=2 face=Arial></FONT></SPAN>&nbsp;</DIV>
<DIV>&nbsp;</DIV><!-- Converted from text/plain format -->
<P><FONT size=2>--<BR>Bernd Becker&nbsp;&nbsp; Climate Impacts Product 
Development<BR>Met Office Hadley Centre&nbsp;&nbsp;&nbsp; FitzRoy Road&nbsp; 
Exeter&nbsp;&nbsp; Devon EX1 3PB&nbsp; United Kingdom<BR>Tel.: +44 (0) 1392 
884511 Fax: +44 (0)870 900 5050<BR>E-mail:bernd.becker@metoffice.gov.uk - <A 
href="http://www.metoffice.gov.uk/research/our-scientists/seasonal-to-decadal/bernd-becker">http://www.metoffice.gov.uk/research/our-scientists/seasonal-to-decadal/bernd-becker</A><BR><BR></FONT></P>
<DIV>&nbsp;</DIV><BR>
<DIV dir=ltr lang=en-us class=OutlookMessageHeader align=left>
<HR tabIndex=-1>
<FONT size=2 face=Tahoma><B>From:</B> gradsusr-bounces@gradsusr.org 
[mailto:gradsusr-bounces@gradsusr.org] <B>On Behalf Of </B>Arlindo da 
Silva<BR><B>Sent:</B> 04 March 2011 00:33<BR><B>To:</B> GrADS Users 
Forum<BR><B>Subject:</B> Re: [gradsusr] lats4d and used defined 
variable<BR></FONT><BR></DIV>
<DIV></DIV>On Fri, Feb 25, 2011 at 10:00 AM, Becker, Bernd <SPAN dir=ltr>&lt;<A 
href="mailto:bernd.becker@metoffice.gov.uk">bernd.becker@metoffice.gov.uk</A>&gt;</SPAN> 
wrote:<BR>
<DIV class=gmail_quote>
<BLOCKQUOTE 
style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" 
class=gmail_quote><BR>Dear all,<BR>I grapple with lats4d and writing a user 
  defined variable<BR>in grib_format.<BR><BR>How can I achieve the 
  following:<BR><BR>open file.ctl &nbsp;(contains tmax amongst other 
  things)<BR>define pop=tmax/2.<BR><BR>lats4d -v -q -i &nbsp;file.ctl -vars pop 
  &nbsp;-o ex2a -format grads_grib<BR><BR>the follwing works just 
  fine:<BR><BR>lats4d -v -q -i &nbsp;ex2a.ctl -vars tmax &nbsp;-o ex2a -format 
  grads_grib<BR><BR></BLOCKQUOTE>
<DIV><BR></DIV>
<DIV><BR></DIV>
<DIV>Here is something that should work:</DIV>
<DIV><BR></DIV>
<DIV>lats4d -v -q -i &nbsp;ex2a.ctl -vars tmax &nbsp;-func @/2 -o ex2a -format 
grads_grib</DIV>
<DIV><BR></DIV>
<DIV>where '@' will be replaced with the actual variable name. If you really 
want to do something more elaborate it may be better for you to write a gsudf 
function to handle each one of your variables. For example,</DIV>
<DIV><BR></DIV>
<DIV>lats4d -v -q -i &nbsp;ex2a.ctl -vars tmax &nbsp;-func handler(@) &nbsp;-o 
ex2a -format grads_grib</DIV>
<DIV><BR></DIV>
<DIV>Nex you implement the "handler" function in a file called "handler.gsf" 
that you contain something like that:</DIV>
<DIV><BR></DIV>
<DIV>function handler(vname)</DIV>
<DIV>'define xxx = ' vname '/2</DIV>
<DIV>return xxx</DIV>
<DIV><BR></DIV>
<DIV>The script "handler.gsf" needs to be registered as a (grads script) gs UDF 
in your UDXT as explained here:</DIV>
<DIV><BR></DIV>
<DIV>&nbsp;&nbsp; &nbsp;&nbsp;<A 
href="http://opengrads.org/doc/udxt/gsudf/">http://opengrads.org/doc/udxt/gsudf/</A></DIV>
<DIV><BR></DIV>
<DIV>Gs UDF's are very powerful: it allows you to write very complicated 
"expression functions" as a simple grads script. For example, these t-storm 
related functions were written entirely as gs UDFs:</DIV>
<DIV><BR></DIV>
<DIV>&nbsp;&nbsp; &nbsp;&nbsp;<A 
href="http://opengrads.org/doc/udxt/saakeskus/">http://opengrads.org/doc/udxt/saakeskus/</A></DIV>
<DIV><BR></DIV>
<DIV>You will need an opengrads build for using this this feature; use 
v2.0.a9.oga.1 if you can, although it should work in v1.x as well.</DIV>
<DIV><BR></DIV>
<DIV>&nbsp;&nbsp; &nbsp;&nbsp;<A 
href="http://opengrads.org/wiki/index.php?title=Installing_the_OpenGrADS_Bundle">http://opengrads.org/wiki/index.php?title=Installing_the_OpenGrADS_Bundle</A></DIV>
<DIV><BR></DIV>
<DIV>Good Luck,</DIV>
<DIV><BR></DIV>
<DIV>&nbsp;&nbsp; &nbsp; Arlindo</DIV>
<DIV><BR></DIV>
<DIV><BR></DIV>
<DIV>&nbsp;</DIV>
<BLOCKQUOTE 
style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex" 
class=gmail_quote>This runs in a 1.9 built.<BR><BR>In the real case, pop is a 
  lot more complicated than tmax/2.<BR><BR>Thanks for your suggestions!<BR>Have 
  a nice weekend.<BR>Bernd.<BR><BR>--<BR>Bernd Becker &nbsp; Climate Impacts 
  Product Development<BR>Met Office Hadley Centre &nbsp; &nbsp;FitzRoy Road 
  &nbsp;Exeter &nbsp; Devon EX1 3PB &nbsp;United<BR>Kingdom<BR>Tel.: +44 (0) 
  1392 884511 Fax: +44 (0)870 900 5050<BR><A 
  href="mailto:E-mail%3Abernd.becker@metoffice.gov.uk">E-mail:bernd.becker@metoffice.gov.uk</A> 
  -<BR><A 
  href="http://www.metoffice.gov.uk/research/our-scientists/seasonal-to-decadal/bernd-becker" 
  target=_blank>http://www.metoffice.gov.uk/research/our-scientists/seasonal-to-decadal/<BR>bernd-becker</A><BR><BR><BR>_______________________________________________<BR>gradsusr 
  mailing list<BR><A 
  href="mailto:gradsusr@gradsusr.org">gradsusr@gradsusr.org</A><BR><A 
  href="http://gradsusr.org/mailman/listinfo/gradsusr" 
  target=_blank>http://gradsusr.org/mailman/listinfo/gradsusr</A><BR></BLOCKQUOTE></DIV><BR><BR 
clear=all><BR>-- <BR>Arlindo da Silva<BR><A 
href="mailto:dasilva@alum.mit.edu">dasilva@alum.mit.edu</A><BR></BODY></HTML>