home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / hdf / unix / examples.lha / examples / sds / buildsds.c next >
Encoding:
C/C++ Source or Header  |  1991-10-08  |  2.2 KB  |  83 lines

  1. /*************************************************************
  2. **  
  3. **  Program to build an SDS.  User gives size of image, whether
  4. **  or not there should be a scale, whether the scales are
  5. **  uniform or not, and max and min values.
  6. **
  7. **  See the file generate.c for details of what the array looks like.
  8. **
  9. **  Other modules:  calls generate(), which is in file generate.c
  10. **
  11. **  Input file:  none
  12. **  Output file: name given by user on command line
  13. **
  14. **************************************************************/
  15.  
  16.  
  17. #include <stdio.h>
  18. #include <math.h>
  19. #include "df.h"
  20. #define TRUE    1
  21. #define FALSE   0
  22.  
  23. main(argc,argv)
  24. int argc;
  25. char *argv[];
  26. {
  27.     int i, vdim, hdim;
  28.     int make_hscale, make_vscale, use_scales;
  29.     int dimsizes[2];
  30.     long time(), tloc1, tloc2;
  31.     float *data,*hscale, *vscale, max, min;
  32.  
  33.     if (argc < 4) {
  34.       printf("Usage:  %s outfile vdim hdim [[-h] [-v] | [-noscale]]\n",argv[0]);
  35.       exit(1);
  36.     }
  37.  
  38.     dimsizes[0] = vdim = atoi(argv[2]);
  39.     dimsizes[1] = hdim = atoi(argv[3]);
  40.  
  41.     /* determine which non-uniform scales have been requested, and
  42.        whether any scales at all are desired */
  43.     make_hscale=make_vscale = FALSE;
  44.     use_scales = TRUE;
  45.     for (i=4; i<argc; i++) {
  46.         if (strcmp(argv[i],"-h")==0) make_hscale = TRUE;
  47.         if (strcmp(argv[i],"-v")==0) make_vscale = TRUE;
  48.         if (strcmp(argv[i],"-noscale")==0) use_scales = FALSE;
  49.    }
  50.  
  51.     data = (float *) malloc(vdim*hdim*sizeof(float));
  52.     vscale = (float *) malloc(vdim*sizeof(float));
  53.     hscale = (float *) malloc(hdim*sizeof(float));
  54.  
  55.     generate(vdim, hdim, data, vscale, hscale, &max, &min);
  56.  
  57.     i = DFSDsetdims(2,dimsizes);
  58.     i = DFSDsetmaxmin(max, min);
  59.  
  60.     /* handle scales */
  61.     if (use_scales) {
  62.         if (!make_hscale)     /* if -h not chosen, generate simple h scale */
  63.             for (i=0; i<hdim; i++)
  64.                 hscale[i] = i;
  65.         if (!make_vscale)     /* if -v not chosen, generate simple v scale */
  66.             for (i=0; i<vdim; i++) 
  67.                 vscale[i] = i;
  68.     
  69.         i = DFSDsetdimscale(1,vdim,vscale);   /* store the scales */
  70.         i = DFSDsetdimscale(2,hdim,hscale);
  71.     }
  72.  
  73.     DFSDadddata(argv[1], 2,dimsizes,data);
  74.  
  75. }
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.