[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

20060330: dynamic website with Gempak



Chirag,

Now that I'm in my office....

Attached is the source for a program I call showwebgif.
It will read the file from disk, stream the output and
then delete the file from disk. Below is an example of
the usage:
www.unidata.ucar.edu/cgi-bin/rtstats/rtstats_topogif?CONDUIT

The script itself runs a gpmap using the GIF device (in this
case gpmap_gif, though you don't have to use the _gf or _gif
versions, it ensures that you don't have hung "gplt" problems
in the long run), and upon completion of the gif generation
in a $WORK working directory (eg /tmp/latmap.$$) and does 
the following:

######### SNIP ######################
if(-e gempaktopo.gif) then
   $CGIDIR/showwebgif gempaktopo.gif
else
        echo 'Content-type: text/html'
        echo ''
        echo "<html>"
        echo "<Head><Title>TOPOMAP</Title></Head>"
        echo "<Body><H1>Post Results</H1>"
        echo "<pre>"
        cat latmap.log
        echo "</pre>"
        echo "</body>"
        echo "</html>" 
endif

cd /tmp
rm -rf $WORK
############# END SNIP ###############

When sucessful, the showwebgif program will remove the gif file.
If the gpmap program fails to create the gif, an html
page is created. The script then rmoves its working directory
and the gempak .nts files that were created.


You can actually imbed a gif within a web table such as I do here:
http://www/cgi-bin/rtstats/rtstats_sitebyfeed?CONDUIT
By using the <OBJECT> tag (older web browsers may not follow that tag
however). The <td> table cell generation of the script looks like:

echo '<td width="450" style="vertical-align: top">'
echo '<P>'
echo '<A
HREF="http://www.unidata.ucar.edu/cgi-bin/rtstats/rtstats_topogif?'${FEED}'">'
echo '<OBJECT
data="http://www.unidata.ucar.edu/cgi-bin/rtstats/rtstats_topogif?'${FEED}'"
 type="image/gif" width="450px">'
echo 'Topology map'
echo '</OBJECT>'
echo '</a>'
echo '</td>'

The object tag tells the browser to obtain the data from the URL
without the user having to click on the link.

Let me know if you have other questions regarding use of GEMPAK!


Steve Chiswell
Unidata User Support


On Thu, 2006-03-30 at 07:41, Shukla, Chirag wrote:
> Hi Steve,
> 
> This certainly sounds very promising and I like the idea of using MIME
> types. I will give it a try and will let you know how if something goes
> wrong.
> 
> Thanks for the tips :)
> 
> Sincerely,
> Chirag Shukla
> South Dakota State University
> 
> 
> -----Original Message-----
> From: Steve Chiswell [mailto:address@hidden] 
> Sent: Thursday, March 30, 2006 8:00 AM
> To: Shukla, Chirag
> Cc: address@hidden
> Subject: Re: dynamic website with Gempak
> 
> Chirag,
> 
> I do many images from cgi.
> In regard to images, if you expect a large number of requests for
> non-similar images , then you can create them dynamically and then
> instead of putting on your web site for viewing with the normal <IMG
> SRC=""> command, where you will have to maintain the image for some
> period of time- you can send them within the page using a mime type of
> image/gif and immediately delete the file.
> 
> I have a short program for putting the mime block in a web page but it
> is easy to do in perl or php as well. The advantage here I see is that
> you won't risk filling up disk space if your image creation gets
> unexpectedly punded on, and, you don't have to have a directory on your
> web server writable by the web server (web, nobody) process since the
> dynamic page is built and streamed without storing on disk.
> 
> Some examples here are the rtstats web pages under:
> www.unidata.ucar.edu/sortare/idd/rtstats
> and radar images under
> motherlode.ucar.edu/unidata/images/nids/gdradr.html
> 
> If needed, I can put together some web examples for these scripts,
> 
> Steve Chiswell
> Unidata User Support
> 
> On Wed, 29 Mar 2006, Shukla, Chirag wrote:
> 
> > Hi Steve,
> >
> > Hope you are doing excellent.
> >
> > I was thinking of using Gempak as a tool for dynamic 
> > interaction/visualization on websites. Here is what I was thinking:
> > A user submits a form after choosing a date, server side script grabs 
> > data from a database to create a text file followed by calling a .csh 
> > file. The .csh file creates a .gem file and invokes sfmap to create a 
> > temporary image. This image is rendered back to the webpage. Error 
> > checks can be placed in the server side script. Temporary images can 
> > be flushed off every few hours.
> >
> > Someone might have tried this already. Do you think this is a 
> > practical approach?
> >
> > Thanks. Have a great time.
> >
> > Sincerely,
> > Chirag Shukla
> > South Dakota State University
> >
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>

int main(int argc, char *argv[])
{
/************************************************
* Stream a gif image to html output and delete  *
* the file afterwards.                          *
*                                               *
* Usage: showwebgif giffile                     *
*                                               *
* Steve Chiswell                                *
* Unidata/UCAR                                  *
************************************************/
int fp,nbytes;
char tbuf[80];
char *buf;
struct stat sbuf;

if(stat(argv[1],&sbuf) != 0)
   exit(0);

sprintf(tbuf,"Content-type: image/gif\n\0");
write(STDOUT_FILENO,tbuf,strlen(tbuf));
sprintf(tbuf,"Content-length: %d\n\n\0",sbuf.st_size);
write(STDOUT_FILENO,tbuf,strlen(tbuf));

fp = open(argv[1],O_RDONLY);

if(fp > 0)
   {
   buf = (char *)malloc(sbuf.st_size);
   nbytes = read(fp,buf,sbuf.st_size);
   write(STDOUT_FILENO,buf,nbytes);
   free(buf);
   }

close(fp);
unlink(argv[1]);

}