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 >
Wrap
C/C++ Source or Header
|
2017-03-03
|
3KB
|
136 lines
/*
* hdf2ds.c
*
* Take an HDF scientific dataset and send it to a DataScope client.
*
*
* Tim Krauskopf
* National Center for Supercomputing Applications
* October, 1989
*/
#include <stdio.h>
#include <math.h>
#include "df.h"
char
*malloc(),
*xspace,
*yspace, /* storage for scale info */
*slspace; /* intermediate storage */
FILE *fp,*fnames;
int
userle = 0, /* flag indicating need for compression */
comlen=0, /* used for measuring compression */
fd; /* descriptor for output file */
/**********************************************************************/
/* hdf2ds
* Take the list of arguments. Search each file and transfer each of the
* 2D scientific datasets in that file to the DataScope client.
*
* Requires a networking version of NCSA DataScope to operate.
*
*
*/
main(argc,argv)
int argc;
char *argv[];
{
int cd,hostarg,ret,i;
char *malloc(),*p;
if (argc < 2) {
puts(" Usage: hdf2ds hostname filename file2 file3 ...");
exit(1);
}
else
puts(" ==== hdf2ds ====");
if (0 > ds_open(argv[1])) {
puts("*** Cannot open network connection ");
exit(1);
}
for (i=2; i<argc; i++) {
while (!sendone(argv[i]));
}
ds_close(cd);
puts("=== hdf2ds ending");
exit(0);
}
/**********************************************************************/
/* sendone
* Send one file across an open link
*/
sendone(fname)
char *fname;
{
int i,xd,yd,dims[2],ret;
float max,min,*f;
char dlab[256],dummy[256];
ret = DFSDgetdims(fname,&i,dims,2);
if (i != 2 || ret < 0)
return(-1);
printf("=== sending %s %d,%d\n",fname,dims[0],dims[1]);
yd = dims[0];
xd = dims[1];
if (NULL == (slspace = malloc(xd*yd*sizeof(float) + 1000))) {
perror("*** Memory alloc");
exit(1);
}
if (NULL == (xspace = malloc(xd*sizeof(float) + 1000))) {
perror("*** Memory alloc");
exit(1);
}
if (NULL == (yspace = malloc(yd*sizeof(float) + 1000))) {
perror("*** Memory alloc");
exit(1);
}
DFSDgetdata(fname,2, dims, slspace); /* read it */
max = min = 0.0;
DFSDgetmaxmin(&max,&min); /* read max/min */
if (DFSDgetdimscale(1, dims[0], yspace)) { /* read y scale */
f = (float *)yspace;
for (i=0; i<dims[0]; i++)
*f++ = (float)i;
}
if (DFSDgetdimscale(2, dims[1], xspace)) { /* read x scale */
f = (float *)xspace;
for (i=0; i<dims[1]; i++)
*f++ = (float)i;
}
strcpy(dlab,fname);
DFSDgetdatastrs(dlab,dummy,dummy,dummy); /* any stored labels? */
/*
* Note fill in the flags field (second parameter) with any of the
* following:
* G - generate image
* I - interpolated image
* S - save to a file
* R - replace dataset instead of creating a new window for it
*/
ds_send1(dlab,"",max,min,yd,xd,yspace,xspace,slspace);
}