netcdf and web: simple solution

Hi folks.  I'm replying to my own query as to how to make my
webbrowser display netcdf files, in unix X11.

Several folks provided suggestions, and the summary is that one has to
modify both the ~/.mailcap file and the ~/.mime.types file.  The user
also needs a display program that will load up a new x-window, and
that is lacking.  (Another option is to run ncdump in the xterm that
launched netscape, but in my case no such xterm exists.)

So I've written a very simple display program, attached below my
signature in this message.  It's written in c++ and compiles fine with
g++ 2.7.x on my solaris machine.  It merely runs "ncdump -h" and puts
the results in a newly formed X11 window.  There is a toggle switch to
run "ncdump" to see the whole file contents.  The snag is that it uses
the 'libsx' freeware graphics library, and I can't recall at the
moment where the heck I got that from.  (Any ideas?)

Given that I call my display program ncdumpx, and here is the line I
added to my ~/.mailcap file:
  application/x-netcdf; /users/dek/kelley/bin/netcdf/ncdumpx %s
and here is the line I added to my ~/.mime.types file:
  application/x-netcdf            nc cdf

I hope my little program is of use to folks out there.  If anybody can
knows of the source of the libsx software, or cares to rewrite ncdumpx
in more standard X11 code, please post a followup to this.

Again, thanks to the several people who helped me on this.

Dan.

Dan E. Kelley                   internet:         mailto:Dan.Kelley@xxxxxx
Oceanography Department         phone:                       (902)494-1694
Dalhousie University            fax:                         (902)494-2885
Halifax, NS, CANADA, B3H 4J1    WWW:  http://www.phys.ocean.dal.ca/~kelley

/*
 * ncdumpx.cc -- dump netcdf file to X11 window
 *
 * Author -- Dan Kelley, <Dan.Kelley@xxxxxx>
 *
 * (c) 1996
 *
 * NOTES: This uses the X11 library called libsx.  Unfortunately
 * I don't know where this is located at present.  My notes
 * from 1995 indicate that it was once located on 
 * ftp.sgi.com in the directory named pub.  But I can't
 * see it there now, March 1996.
 *
 * COMPILATION: Compile by the command
 *   c++ -o ncdumpx ncdumpx.cc \
 *     -D_POSIX_SOURCE -I/usr/openwin/include \
 *     -I /users/dek/kelley/src/libsx/src \
 *     /users/dek/kelley/src/libsx/src/libsx.a \
 *     -lXaw -lXmu -lXt -lX11
 *
 * $Id: ncdumpx.cc,v 1.4 1996/04/04 17:26:23 kelley Exp $
 */


#include <stdlib.h>
#include <stdio.h>
#include "libsx.h"

// Globals
Widget text_pane;               // used by header_only()
char *fname;                    // netcdf filename
bool only_header = true;        // flag for header_only vs header_plus_data
char *tmp_fname;                // temporary filename

void
quit(Widget w, void *data)      // quit
{
    char cmd[1024];
    sprintf(cmd, "rm -f %s\n", tmp_fname);
    system(cmd);
    exit(0);
}

void
make_tmp_file()                 // prepare file to display
{
    char cmd[1024];
    if (only_header)
        sprintf(cmd, "ncdump -h %s > %s", fname, tmp_fname);
    else
        sprintf(cmd, "ncdump    %s > %s", fname, tmp_fname);
    system(cmd);
}

void
header_only(Widget w, void *data)
{
    only_header = !only_header;
    make_tmp_file();
    SetTextWidgetText(text_pane, tmp_fname, 1);
}

int
main(int argc, char *argv[])
{
    if (argc != 2) {
        fprintf(stderr, "Usage: %s file.nc\n", argv[0]);
        exit(1);
    }
    tmp_fname = tmpnam(NULL);
    argc = OpenDisplay(argc, argv);
    fname = argv[1];
    Widget label = MakeLabel(argv[1]);
    XFont xf = GetWidgetFont(label);
    make_tmp_file();            // sets tmp_fname
    int edit_file = 1, no_modify = 1, width = 400, height = 300;
    text_pane          = MakeTextWidget(tmp_fname, edit_file, no_modify, width, 
height);
    Widget quit_button = MakeButton("Quit", quit, NULL);
    Widget header = MakeToggle("Show Data?", 1, NULL, header_only, NULL);
    SetWidgetPos(text_pane,   PLACE_UNDER, label,     NO_CARE, NULL);
    SetWidgetPos(quit_button, PLACE_UNDER, text_pane, NO_CARE, NULL);
    SetWidgetPos(header,      PLACE_UNDER, text_pane, PLACE_RIGHT, quit_button);
    MainLoop();
}


  • 1996 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the netcdfgroup archives: