home *** CD-ROM | disk | FTP | other *** search
/ ftp.ncsa.uiuc.edu / ftp.ncsa.uiuc.edu.zip / ftp.ncsa.uiuc.edu / DataScope / misc / hdf2ds.c < prev    next >
C/C++ Source or Header  |  2017-03-03  |  3KB  |  136 lines

  1. /*
  2. *  hdf2ds.c
  3. *
  4. *  Take an HDF scientific dataset and send it to a DataScope client.
  5. *
  6. *
  7. *  Tim Krauskopf
  8. *  National Center for Supercomputing Applications
  9. *  October, 1989
  10. */
  11.  
  12. #include <stdio.h>
  13. #include <math.h>
  14. #include "df.h"
  15.  
  16.  
  17. char 
  18.     *malloc(),
  19.     *xspace,
  20.     *yspace,            /* storage for scale info */
  21.     *slspace;            /* intermediate storage */
  22.  
  23. FILE *fp,*fnames;
  24. int 
  25.     userle = 0,            /* flag indicating need for compression */
  26.     comlen=0,            /* used for measuring compression */
  27.     fd;                    /* descriptor for output file */
  28.  
  29.  
  30. /**********************************************************************/
  31. /*  hdf2ds
  32. *   Take the list of arguments.  Search each file and transfer each of the
  33. *   2D scientific datasets in that file to the DataScope client.
  34. *
  35. *   Requires a networking version of NCSA DataScope to operate.
  36. *
  37. *
  38. */
  39.  
  40. main(argc,argv)
  41.     int argc;
  42.     char *argv[];
  43.     {
  44.     int cd,hostarg,ret,i;
  45.     char *malloc(),*p;
  46.  
  47.     if (argc < 2) {
  48.         puts(" Usage: hdf2ds hostname filename file2 file3 ...");
  49.         exit(1);
  50.     }
  51.     else 
  52.         puts(" ====  hdf2ds  ====");
  53.  
  54.     if (0 > ds_open(argv[1])) {
  55.         puts("*** Cannot open network connection ");
  56.         exit(1);
  57.     }
  58.  
  59.  
  60.     for (i=2; i<argc; i++) { 
  61.         while (!sendone(argv[i]));
  62.     }
  63.  
  64.  
  65.     ds_close(cd);
  66.  
  67.     puts("=== hdf2ds ending");
  68.     exit(0);
  69. }
  70.  
  71. /**********************************************************************/
  72. /*  sendone
  73. *   Send one file across an open link
  74. */
  75. sendone(fname)
  76.     char *fname;
  77.     {
  78.     int i,xd,yd,dims[2],ret;
  79.     float max,min,*f;
  80.     char dlab[256],dummy[256];
  81.  
  82.     ret = DFSDgetdims(fname,&i,dims,2);
  83.  
  84.     if (i != 2 || ret < 0)
  85.         return(-1);
  86.  
  87.     printf("=== sending %s  %d,%d\n",fname,dims[0],dims[1]);
  88.  
  89.     yd = dims[0];
  90.     xd = dims[1];
  91.  
  92.     if (NULL == (slspace = malloc(xd*yd*sizeof(float) + 1000))) {
  93.         perror("*** Memory alloc");
  94.         exit(1);
  95.     }
  96.     if (NULL == (xspace = malloc(xd*sizeof(float) + 1000))) {
  97.         perror("*** Memory alloc");
  98.         exit(1);
  99.     }
  100.     if (NULL == (yspace = malloc(yd*sizeof(float) + 1000))) {
  101.         perror("*** Memory alloc");
  102.         exit(1);
  103.     }
  104.  
  105.     DFSDgetdata(fname,2, dims, slspace);          /* read it */
  106.     max = min = 0.0;
  107.     DFSDgetmaxmin(&max,&min);                    /* read max/min */
  108.     if (DFSDgetdimscale(1, dims[0], yspace)) {    /* read y scale */
  109.         f = (float *)yspace;
  110.         for (i=0; i<dims[0]; i++)
  111.             *f++ = (float)i;
  112.     }
  113.  
  114.     if (DFSDgetdimscale(2, dims[1], xspace)) {    /* read x scale */
  115.         f = (float *)xspace;
  116.         for (i=0; i<dims[1]; i++)
  117.             *f++ = (float)i;    
  118.     }
  119.  
  120.     strcpy(dlab,fname);
  121.     DFSDgetdatastrs(dlab,dummy,dummy,dummy);    /* any stored labels? */
  122.  
  123. /*
  124. *  Note fill in the flags field (second parameter) with any of the
  125. *  following:
  126. *  G - generate image
  127. *  I - interpolated image
  128. *  S - save to a file
  129. *  R - replace dataset instead of creating a new window for it
  130. */
  131.  
  132.     ds_send1(dlab,"",max,min,yd,xd,yspace,xspace,slspace);
  133.  
  134. }
  135.  
  136.