File: minc_types.c

package info (click to toggle)
libminc 2.4.07-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,288 kB
  • sloc: ansic: 57,268; cpp: 3,654; sh: 100; makefile: 23; ruby: 18
file content (120 lines) | stat: -rw-r--r-- 3,400 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/* ----------------------------- MNI Header -----------------------------------
@NAME       : test
@INPUT      : 
@OUTPUT     : 
@RETURNS    : 
@DESCRIPTION: 
@METHOD     : 
@GLOBALS    : 
@CALLS      : 
@CREATED    : 
@MODIFIED   : 
---------------------------------------------------------------------------- */
#if HAVE_CONFIG_H
#include "config.h"
#endif

#include <stdlib.h>
#include <stdio.h>
#include <float.h>
#include <limits.h>
#include <minc.h>

#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif

#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif

#include <string.h>


static struct {
   nc_type type;
   char *sign;
   char *ctype;

} types[]= { { NC_BYTE,   MI_UNSIGNED, "byte" },
	     { NC_BYTE,   MI_SIGNED,   "byte" },
	     { NC_SHORT,  MI_UNSIGNED, "short" },
	     { NC_SHORT,  MI_SIGNED,   "short" },
	     { NC_INT,    MI_UNSIGNED, "int" },
	     { NC_INT,    MI_SIGNED,   "int" },
	     { NC_FLOAT,  MI_SIGNED,   "float" },
	     { NC_DOUBLE, MI_SIGNED,   "double" } };
static const int ntypes = sizeof(types)/sizeof(types[0]);

int main(int argc, char **argv)
{
   int cdf;
   int img, img2;
   int dim[MAX_VAR_DIMS];
   long start[MAX_VAR_DIMS];
   long count[MAX_VAR_DIMS];
   double image[256*256];
   int i, itype, jtype;
   int cflag = 0;
   char filename[256];

#if MINC2
   if (argc == 2 && !strcmp(argv[1], "-2")) {
       cflag = MI2_CREATE_V2;
   }
#endif /* MINC2 */

   snprintf(filename, sizeof(filename), "test_minc_types-%d.mnc", getpid());

   set_ncopts(NC_VERBOSE|NC_FATAL);
   for (itype=0; itype<ntypes; itype++) {
      for (jtype=0; jtype<ntypes; jtype++) {
         cdf=micreate(filename, NC_CLOBBER | cflag);
         count[2]=256;
         count[1]=20;
         count[0]=7;
         dim[2]=ncdimdef(cdf, MIzspace, count[2]);
         dim[1]=ncdimdef(cdf, MIxspace, count[1]);
         dim[0]=ncdimdef(cdf, MIyspace, count[0]);
         img=ncvardef(cdf, MIimage, types[itype].type, 1, dim);
         (void) miattputstr(cdf, img, MIsigntype, types[itype].sign);
         img2=ncvardef(cdf, "image2", types[jtype].type, 1, dim);
         (void) miattputstr(cdf, img2, MIsigntype, types[jtype].sign);
         image[0]=10.0;
         image[1]=2.0*(-FLT_MAX);
         image[2]=2.0*FLT_MAX;
         image[3]=3.2;
         image[4]=3.7;
         image[5]=(-3.2);
         image[6]=(-3.7);
#if 0
   for (j=0; j<count[0]; j++) {
      for (i=0; i<count[1]; i++) {
         ioff=(j*count[1]+i)*count[2];
         for (k=0; k<count[2]; k++)
            image[ioff+k]=ioff+k+10;
      }
   }
#endif
         (void) ncendef(cdf);
         (void) miset_coords(3,0L,start);
         (void) mivarput(cdf, img, start, count, NC_DOUBLE, NULL, image);

         (void) mivarget(cdf, img, start, count, types[jtype].type,
                         types[jtype].sign, image);
         (void) mivarput(cdf, img2, start, count, types[jtype].type,
                         types[jtype].sign, image);

         (void) mivarget(cdf, img2, start, count, NC_DOUBLE, NULL, image);
         (void) printf("Image 1 : %s %s\n",types[itype].sign,
                       types[itype].ctype);
         (void) printf("Image 2 : %s %s\n",types[jtype].sign,
                       types[jtype].ctype);
         for (i=0;i<count[0];i++)
            (void) printf("   image[%d] = %g\n",(int) i, image[i]);
         (void) miclose(cdf);
      }
   }
   unlink(filename);
   return(0);
}