From: Arlindo da S. <da...@al...> - 2008-06-25 12:20:27
|
On Tue, Jun 24, 2008 at 11:46 PM, Luiz Rodrigo Tozzi < lui...@gm...> wrote: > Hi Arlindo > > After reading the Gerl code and using it, I managed to translate the > idea from Perl to PHP. This is very nice! You got something already very functional. > PHP is a bit different from Perl because there > is no prompt to deal with PHP commands, only the interpreter of the > command line or the web based interpreter. > Even in perl, most times I just write a script. > > I began to write the PHP interface and now I can open the grads with > the -u option, with bidirectional pipe. Some of the most common used > commands are implemented. For an example: > [...] > I'm preparing the code to the Echo/Verb style you did in the Gerl and > I can send you this first version of the code for you to have a look. > These get really important for debugging. In batch sometimes one wants to suppress most output except when something goes wrong. > > Is there something I forgot for this first pre-alpha prototype? I'm > open for sugestions! > I see that you started with a non-OO prototype. The main advantage of an OO interface is that you can instantiate more than one version of GrAS at a time. For example when dealing with HDF and OPeNDAP files in v1.9 one end up having to start 2 instances (one with gradshdf, another with gradsdods). Another advantage of an OO approach is that it makes it easy to extended it n different directions, while retaining the core functionality in a base class. > > I'm interested in handling the graphical output of GrADS through GD > but I don't know how to do it. I used to deal with GD programming in > PHP but i don't know how it works in GrADS. > I am not clear exactly what kind of things would you like to do. You can always write PNG from GrADS and read it from disk. You could also capture the GrADS metafile through the pipe (I'd need to add an simple grads extension for that) and then use GD interface to PHP to create the image in PHP. (I'd recommend cairo over GD as it is more capable.) One question: does PHP have any way of efficiently representing numerical arrays? Again, congratulations! This is very exciting work. I look forward to distribut it through opengrads as another interface to GrADS. Perhaps we could start checking in to the repository what you already have. Cheers! Arlindo ---- original message ---- Hi Arlindo After reading the Gerl code and using it, I managed to translate the idea from Perl to PHP. PHP is a bit different from Perl because there is no prompt to deal with PHP commands, only the interpreter of the command line or the web based interpreter. I began to write the PHP interface and now I can open the grads with the -u option, with bidirectional pipe. Some of the most common used commands are implemented. For an example: #!/usr/bin/php <?php include ("gradsPHP.php"); // OPEN GRADS WITH OR WITHOUT OPTIONS grads(array( "Bin" => "gradsnc", "Echo" => "0", "Opt" => "-b" )); // or just grads(); // OPEN THE FILE ga_open("model.nc","nc"); // SET LAT, LON, ETC ga_set("lat","-23.8 -12.6"); ga_set("lon","-52.2 -39.4"); ga_set("gxout","shaded"); ga_set("grads","off"); // DISPLAY PS ga_display("ps"); // DRAW THE TITLE CONTROLLING THE POSITION OF THE TITLE ga_title("Pressao - Minas Gerais",$opt=array("Font"=>"0","Size"=>".25","YOffset"=>".2")); // CBARN AND SHAPE CONTOURS ga_cmd("run cbarn.gs"); ga_set("line","0"); ga_cmd("shp_lines est"); ga_cmd("shp_lines mun"); //ga_query("pos"); // EXPORT THE IMAGE ga_gxyat("ok.png"); // CLOSE PIPES, PID... ga_submit(); // SHOW THE IMAGE `animate ok.png`; ?> This is a "tutorial like program", where I used the gradsPHP.php functions that arrange the commands and send them to grads through the pipe. I create the ga_title() function based in Jennifer's title.gs script, but in this case you can pass some attributes through an array of options, including the Y position of the title. I obtain this information using the "q gxinfo" and retriving the output using the pipe system. The ga_cmd() function is the most generic function of the class. It can send the commands like: ga_cmd("set x 1"); ga_cmd("set y 1"); ga_cmd("d ps"); ga_cmd("draw title something"); or ga_cmd(" set x 1 set y 1 d ps draw title something "); or even ga_cmd($scriptgs); [$scriptgs is the content of a gs file] I'm preparing the code to the Echo/Verb style you did in the Gerl and I can send you this first version of the code for you to have a look. Is there something I forgot for this first pre-alpha prototype? I'm open for sugestions! I'm interested in handling the graphical output of GrADS through GD but I don't know how to do it. I used to deal with GD programming in PHP but i don't know how it works in GrADS. Peace! -- Luiz Rodrigo Lins Tozzi lui...@gm... -- Arlindo da Silva da...@al... |
From: Arlindo da S. <da...@al...> - 2008-07-02 05:20:47
|
Rodrigo, A quick answer before bedtime. On Wed, Jul 2, 2008 at 12:11 AM, Luiz Rodrigo Tozzi < lui...@gm...> wrote: > Hi Arlindo > > I'm sending to you the first prototype of the PHP interface, for you to > test and see what I did until now. > > I spent some time trying to figure out how PHP deals with the data stream > between grads and the PHP pipe system. I think I'll have to test it more > along with the getError() function. For really basic stuff, its functional. > That sounds great. I'll take a look at it and check it in to the repository. It would be good if you could use the repo for maintaining the PHP interface. Are you familiar with CVS? Also, I'd need your sourceforge userid to give you commit privileges to the repository and to the wiki. > > Just like you suggested in the previous email, I rewrote the functions to > be OO based and I organized it better. Now all of the functions obey the > Echo and Verb-like output flags and most of the functions are able to handle > this output in a raw way or in an array way. > Nice. > > In the this tarball there are two simple examples of how it works. > grads_shaded.php is a step by step script that only opens a nc file, sets > the environment and plots an image. grads_points.php is a php script that > coordinates a series of calls to retrieve variable values from some points > using arrays, loops and other php stuff. this grads_points.php could receive > the points coordinates and names from a MySQL database, get some information > through GrADS and show it in a HTML-like PHP in the server. I already did > that but creating the gs file and submiting into GrADS. Now it can be done > within the PHP script! > One of the advantage of this approach is that you can parse the output of each grads command and handle it appropriately if an error occurs. > > > I'm interested in handling the graphical output of GrADS through GD >>> but I don't know how to do it. I used to deal with GD programming in >>> PHP but i don't know how it works in GrADS. >>> >> >> >> I am not clear exactly what kind of things would you like to do. You can >> always write PNG from GrADS and read it from disk. You could also capture >> the GrADS metafile through the pipe (I'd need to add an simple grads >> extension for that) and then use GD interface to PHP to create the image in >> PHP. (I'd recommend Cairo over GD as it is more capable.) >> > > I noticed that using libipc I can get some slice of data and that's what > I'm about to try now, but I was asking about capturing the GrADS metafile. > In PHP, as in your Python interface, there are powerful tools to handle > graphics, using GD or Cairo. One of those applications is the web based > capability of displaying something you dynamically created. In my > applications I can place a PNG over a satellite image using alpha channels > and transparency, add text with TTF font, with "Portuguese characters" and > use the image area completely, with no blanks in the sides. > > The point is: is it possible to add this grads extension, to handle GrADS > metafile? > Yes, the gxyat extension extracts the metafile instructions and renders it using cairo (from C). The idea is to add a function to IPC that grabs the metafile instructions and writes it to stdout so that the extensions can handle it. In PyGrADS I'd like to render it with Matplotlib on top of a blue marble basemap or a satellite image (the PyGrADS screenshots are plotted exclusively with Matplotlib). Now, gxyat can write SVG which cairo can handle (of course, cairo wrote it) so this could be a viable initial path to get the GrADS vector graphics instructions into PHP. > >> One question: does PHP have any way of efficiently representing numerical >> arrays? >> >> > If you are asking about n dimensional arrays, lists, vectors and things > like these the answer is yes. Its not hard to work with it but I really dont > know if there is a limit to the size of objects or something like it. But > its easy to implement. > Perl and Python also have "arrays" but these are really "lists" and are very inefficient for numerical work. PDL in perl and numpy in Python are extensions for efficient handling of numerical n-dimensional arrays. Does PHP have anything similar? > > I just subscribed to opengrads-devel list and I saw that you are working on > a Matlab interface. Do you know if someone has ever tried to do a "R" (< > http://www.r-project.org/>) interface? I used to work on it and its a very > useful environment. > Funny that you ask. I was looking into R yesterday. However, I found out that I could use R from Python using the Rpy extension. It seems to work well on my Mac. One might be able to develop a native R interface to GrADS but I do not know much about R internals myself, and the python route works me. If you have any interest, go for it. > > By the way, there is something off-topic that I'm curious about: your name > looks like a Portuguese-like name. Are you from Brazil or Portugal? Have you > ever been here in Brazil? There are lots of people from here in the GrADS > user list, specially in CPTEC, where I used to work. You may know José > Pesquero, he is a heavy user from the GrADS list and a friend of mine. > Yes, I am from Niteroi and visited CPTEC many times. I helped them implement PSAS for both regional and global data assimilation. Yes, I know Pesquero for some time. BTW, Pedro invited me for a round table this summer at CBMET, so I might be coming to Sao Paulo in August. Cheers, Arlindo -- Arlindo da Silva da...@al... |
From: Arlindo da S. <da...@al...> - 2008-07-02 19:21:24
|
On Wed, Jul 2, 2008 at 10:30 AM, Luiz Rodrigo Tozzi < lui...@gm...> wrote: > > Great. That will be my next step as soon as the IPC extension were able to > deal with metafile instructions. I have tons of php scripts that extract > information from a MySQL db and use GD to plot meteograms and graphs using > JpGraph (http://www.aditus.nu/jpgraph/). unfortunately this program is not > entirely free :( > the development to Cairo is only beginning in PHP but start from here is > something really interesting. > The gxyat extension can write SVG right now: ga-> d ts ga-> gxyat ts.svg SVG is an XML ASCII format for vector graphics; there is some PHP support for it. Capturing the SVG through the pipe can be done with minimal work. SVG is complex but the kinds of files written by gxyat are simple. Capturing the GrADS metafile binary format is also an option. You can prototype this by writing it to disk with print. Getting it through the pipe would be an optimization step for increasing performance, nothing more. Arlindo -- Arlindo da Silva da...@al... |
From: Luiz R. T. <lui...@gm...> - 2008-07-02 20:03:41
|
Ok, Arlindo I'll work on it using "display => gxyat => svg file => php" and once its stable I'll try using "display => php pipe" I'll keep on writing the php code and, as soon as I have the permission, I'll place it in the CVS. Peace -- Luiz Rodrigo Lins Tozzi lui...@gm... http://thedealwith.blogspot.com/ On Wed, Jul 2, 2008 at 4:21 PM, Arlindo da Silva <da...@al...> wrote: > On Wed, Jul 2, 2008 at 10:30 AM, Luiz Rodrigo Tozzi < > lui...@gm...> wrote: > >> >> Great. That will be my next step as soon as the IPC extension were able to >> deal with metafile instructions. I have tons of php scripts that extract >> information from a MySQL db and use GD to plot meteograms and graphs using >> JpGraph (http://www.aditus.nu/jpgraph/). unfortunately this program is >> not entirely free :( >> the development to Cairo is only beginning in PHP but start from here is >> something really interesting. >> > > The gxyat extension can write SVG right now: > > ga-> d ts > ga-> gxyat ts.svg > > SVG is an XML ASCII format for vector graphics; there is some PHP support > for it. Capturing the SVG through the pipe can be done with minimal work. > SVG is complex but the kinds of files written by gxyat are simple. Capturing > the GrADS metafile binary format is also an option. You can prototype this > by writing it to disk with print. Getting it through the pipe would be an > optimization step for increasing performance, nothing more. > > Arlindo > > > > -- > Arlindo da Silva > da...@al... > |
From: Arlindo da S. <da...@al...> - 2008-07-03 02:32:55
|
Luiz, I have added you to the OpenGrADS project on sf.net and also on the OpenGrADS wiki (we do not use the sf.net wiki because it is not MediaWiki, so the wiki account is separate from sf.net). A couple of notes: 1) I have checked in your tarball and created a CVS module that includes our generic test data directory. For checking it out: export CVS_RSH=ssh cvs -z3 -d:ext:lui...@op...:/cvsroot/opengrads co -P gradsPHP* *Unless you have setup your SSH keys this will ask for your sf.net password. For SSH key info check this: http://alexandria.wiki.sourceforge.net/SSH+Key+Generation I strongly recommend you setup your ssh keys for passwordless access to cvs. 2) I have not checked in your shapefiles because I was not sure whether they were freely available; sf.net does not allow check in of proprietary data/software. It must be covered by some form of opensource license. BTW, the model.nc file is under data, you may need to adjust your test script. 3) I have created stubs for the standard files COPYING, README, INSTALL, etc. Please populate these files when you have a chance. Take a look at one of the other packages for examples, e.g., cvs .... co -P pygrads cvs ... co -P gerl 4) You should have received an e-mail with your wiki password. I have created a place holder wiki page for the PHP interface: http://opengrads.org/wiki/index.php?title=PHP_Interface_to_GrADS Edit it as you see fit. This is just a copy of the Perl wiki now. 5) You need to add licensing terms to each source file, and also in the COPYING file. Most of my stuff is under GPL, some under a Perl style license term. See the gerl/pygrads packages for examples. Sourceforge requires an opensource license. I was able to sucessfully run your test scripts on my Mac running Leopard. It ran out of the box! Let me know if you have questions, Arlindo On Wed, Jul 2, 2008 at 12:11 AM, Luiz Rodrigo Tozzi < lui...@gm...> wrote: > Hi Arlindo > > I'm sending to you the first prototype of the PHP interface, for you to > test and see what I did until now. > > I spent some time trying to figure out how PHP deals with the data stream > between grads and the PHP pipe system. I think I'll have to test it more > along with the getError() function. For really basic stuff, its functional. > > Just like you suggested in the previous email, I rewrote the functions to > be OO based and I organized it better. Now all of the functions obey the > Echo and Verb-like output flags and most of the functions are able to handle > this output in a raw way or in an array way. > > In the this tarball there are two simple examples of how it works. > grads_shaded.php is a step by step script that only opens a nc file, sets > the environment and plots an image. grads_points.php is a php script that > coordinates a series of calls to retrieve variable values from some points > using arrays, loops and other php stuff. this grads_points.php could receive > the points coordinates and names from a MySQL database, get some information > through GrADS and show it in a HTML-like PHP in the server. I already did > that but creating the gs file and submiting into GrADS. Now it can be done > within the PHP script! > > > I'm interested in handling the graphical output of GrADS through GD >>> but I don't know how to do it. I used to deal with GD programming in >>> PHP but i don't know how it works in GrADS. >>> >> >> >> I am not clear exactly what kind of things would you like to do. You can >> always write PNG from GrADS and read it from disk. You could also capture >> the GrADS metafile through the pipe (I'd need to add an simple grads >> extension for that) and then use GD interface to PHP to create the image in >> PHP. (I'd recommend Cairo over GD as it is more capable.) >> > > I noticed that using libipc I can get some slice of data and that's what > I'm about to try now, but I was asking about capturing the GrADS metafile. > In PHP, as in your Python interface, there are powerful tools to handle > graphics, using GD or Cairo. One of those applications is the web based > capability of displaying something you dynamically created. In my > applications I can place a PNG over a satellite image using alpha channels > and transparency, add text with TTF font, with "Portuguese characters" and > use the image area completely, with no blanks in the sides. > > The point is: is it possible to add this grads extension, to handle GrADS > metafile? > > >> One question: does PHP have any way of efficiently representing numerical >> arrays? >> >> > If you are asking about n dimensional arrays, lists, vectors and things > like these the answer is yes. Its not hard to work with it but I really dont > know if there is a limit to the size of objects or something like it. But > its easy to implement. > > I just subscribed to opengrads-devel list and I saw that you are working on > a Matlab interface. Do you know if someone has ever tried to do a "R" (< > http://www.r-project.org/>) interface? I used to work on it and its a very > useful environment. > > By the way, there is something off-topic that I'm curious about: your name > looks like a Portuguese-like name. Are you from Brazil or Portugal? Have you > ever been here in Brazil? There are lots of people from here in the GrADS > user list, specially in CPTEC, where I used to work. You may know José > Pesquero, he is a heavy user from the GrADS list and a friend of mine. > > Peace! > > -- > > Luiz Rodrigo Lins Tozzi > lui...@gm... > http://thedealwith.blogspot.com/ > > On Wed, Jun 25, 2008 at 9:20 AM, Arlindo da Silva <da...@al...> > wrote: > >> On Tue, Jun 24, 2008 at 11:46 PM, Luiz Rodrigo Tozzi < >> lui...@gm...> wrote: >> >>> Hi Arlindo >>> >>> After reading the Gerl code and using it, I managed to translate the >>> idea from Perl to PHP. >> >> >> This is very nice! You got something already very functional. >> >> >>> PHP is a bit different from Perl because there >>> is no prompt to deal with PHP commands, only the interpreter of the >>> command line or the web based interpreter. >>> >> >> Even in perl, most times I just write a script. >> >> >>> >>> I began to write the PHP interface and now I can open the grads with >>> the -u option, with bidirectional pipe. Some of the most common used >>> commands are implemented. For an example: >>> >> >> [...] >> >> >>> I'm preparing the code to the Echo/Verb style you did in the Gerl and >>> I can send you this first version of the code for you to have a look. >>> >> >> These get really important for debugging. In batch sometimes one wants to >> suppress most output except when something goes wrong. >> >> >>> >>> Is there something I forgot for this first pre-alpha prototype? I'm >>> open for sugestions! >>> >> >> I see that you started with a non-OO prototype. The main advantage of an >> OO interface is that you can instantiate more than one version of GrAS at a >> time. For example when dealing with HDF and OPeNDAP files in v1.9 one end up >> having to start 2 instances (one with gradshdf, another with gradsdods). >> Another advantage of an OO approach is that it makes it easy to extended it >> n different directions, while retaining the core functionality in a base >> class. >> >> >>> >>> I'm interested in handling the graphical output of GrADS through GD >>> but I don't know how to do it. I used to deal with GD programming in >>> PHP but i don't know how it works in GrADS. >>> >> >> >> I am not clear exactly what kind of things would you like to do. You can >> always write PNG from GrADS and read it from disk. You could also capture >> the GrADS metafile through the pipe (I'd need to add an simple grads >> extension for that) and then use GD interface to PHP to create the image in >> PHP. (I'd recommend cairo over GD as it is more capable.) >> >> One question: does PHP have any way of efficiently representing numerical >> arrays? >> >> Again, congratulations! This is very exciting work. I look forward to >> distribut it through opengrads as another interface to GrADS. Perhaps we >> could start checking in to the repository what you already have. >> >> Cheers! >> >> Arlindo >> >> >> ---- original message ---- >> >> Hi Arlindo >> >> After reading the Gerl code and using it, I managed to translate the >> idea from Perl to PHP. PHP is a bit different from Perl because there >> is no prompt to deal with PHP commands, only the interpreter of the >> command line or the web based interpreter. >> >> I began to write the PHP interface and now I can open the grads with >> the -u option, with bidirectional pipe. Some of the most common used >> commands are implemented. For an example: >> >> #!/usr/bin/php >> <?php >> include ("gradsPHP.php"); >> >> // OPEN GRADS WITH OR WITHOUT OPTIONS >> grads(array( >> "Bin" => "gradsnc", >> "Echo" => "0", >> "Opt" => "-b" >> )); >> // or just grads(); >> >> // OPEN THE FILE >> ga_open("model.nc","nc"); >> >> // SET LAT, LON, ETC >> ga_set("lat","-23.8 -12.6"); >> ga_set("lon","-52.2 -39.4"); >> ga_set("gxout","shaded"); >> ga_set("grads","off"); >> >> // DISPLAY PS >> ga_display("ps"); >> >> // DRAW THE TITLE CONTROLLING THE POSITION OF THE TITLE >> ga_title("Pressao - Minas >> Gerais",$opt=array("Font"=>"0","Size"=>".25","YOffset"=>".2")); >> >> // CBARN AND SHAPE CONTOURS >> ga_cmd("run cbarn.gs"); >> ga_set("line","0"); >> ga_cmd("shp_lines est"); >> ga_cmd("shp_lines mun"); >> //ga_query("pos"); >> >> // EXPORT THE IMAGE >> ga_gxyat("ok.png"); >> >> // CLOSE PIPES, PID... >> ga_submit(); >> >> // SHOW THE IMAGE >> `animate ok.png`; >> >> ?> >> >> This is a "tutorial like program", where I used the gradsPHP.php >> functions that arrange the commands and send them to grads through the >> pipe. >> >> I create the ga_title() function based in Jennifer's title.gs script, >> but in this case you can pass some attributes through an array of >> options, including the Y position of the title. I obtain this >> information using the "q gxinfo" and retriving the output using the >> pipe system. >> >> The ga_cmd() function is the most generic function of the class. It >> can send the commands like: >> >> ga_cmd("set x 1"); >> ga_cmd("set y 1"); >> ga_cmd("d ps"); >> ga_cmd("draw title something"); >> >> or >> >> ga_cmd(" >> set x 1 >> set y 1 >> d ps >> draw title something >> "); >> >> or even >> >> ga_cmd($scriptgs); >> >> [$scriptgs is the content of a gs file] >> >> >> I'm preparing the code to the Echo/Verb style you did in the Gerl and >> I can send you this first version of the code for you to have a look. >> >> Is there something I forgot for this first pre-alpha prototype? I'm >> open for sugestions! >> >> I'm interested in handling the graphical output of GrADS through GD >> but I don't know how to do it. I used to deal with GD programming in >> PHP but i don't know how it works in GrADS. >> >> >> Peace! >> >> -- >> >> Luiz Rodrigo Lins Tozzi >> lui...@gm... >> >> -- >> Arlindo da Silva >> da...@al... > > > -- Arlindo da Silva da...@al... |