1 /* ----------------------------- MNI Header -----------------------------------
2 @NAME : test
3 @INPUT :
4 @OUTPUT :
5 @RETURNS :
6 @DESCRIPTION:
7 @METHOD :
8 @GLOBALS :
9 @CALLS :
10 @CREATED :
11 @MODIFIED :
12 ---------------------------------------------------------------------------- */
13 #if HAVE_CONFIG_H
14 #include "config.h"
15 #endif
16
17 #include <stdlib.h>
18 #include <stdio.h>
19 #include <float.h>
20 #include <limits.h>
21 #include <minc.h>
22
23 struct {
24 nc_type type;
25 char *sign;
26 char *ctype;
27
28 } types[]= { { NC_BYTE, MI_UNSIGNED, "byte" },
29 { NC_BYTE, MI_SIGNED, "byte" },
30 { NC_SHORT, MI_UNSIGNED, "short" },
31 { NC_SHORT, MI_SIGNED, "short" },
32 { NC_INT, MI_UNSIGNED, "int" },
33 { NC_INT, MI_SIGNED, "int" },
34 { NC_FLOAT, MI_SIGNED, "float" },
35 { NC_DOUBLE, MI_SIGNED, "double" } };
36 int ntypes = sizeof(types)/sizeof(types[0]);
37
main(int argc,char ** argv)38 int main(int argc, char **argv)
39 {
40 int cdf;
41 int img, img2;
42 int dim[MAX_VAR_DIMS];
43 long start[MAX_VAR_DIMS];
44 long count[MAX_VAR_DIMS];
45 double image[256*256];
46 int i, itype, jtype;
47 int cflag = 0;
48
49 #if MINC2
50 if (argc == 2 && !strcmp(argv[1], "-2")) {
51 cflag = MI2_CREATE_V2;
52 }
53 #endif /* MINC2 */
54
55 ncopts=NC_VERBOSE|NC_FATAL;
56 for (itype=0; itype<ntypes; itype++) {
57 for (jtype=0; jtype<ntypes; jtype++) {
58 cdf=micreate("test.mnc",NC_CLOBBER | cflag);
59 count[2]=256;
60 count[1]=20;
61 count[0]=7;
62 dim[2]=ncdimdef(cdf, MIzspace, count[2]);
63 dim[1]=ncdimdef(cdf, MIxspace, count[1]);
64 dim[0]=ncdimdef(cdf, MIyspace, count[0]);
65 img=ncvardef(cdf, MIimage, types[itype].type, 1, dim);
66 (void) miattputstr(cdf, img, MIsigntype, types[itype].sign);
67 img2=ncvardef(cdf, "image2", types[jtype].type, 1, dim);
68 (void) miattputstr(cdf, img2, MIsigntype, types[jtype].sign);
69 image[0]=10.0;
70 image[1]=2.0*(-FLT_MAX);
71 image[2]=2.0*FLT_MAX;
72 image[3]=3.2;
73 image[4]=3.7;
74 image[5]=(-3.2);
75 image[6]=(-3.7);
76 #if 0
77 for (j=0; j<count[0]; j++) {
78 for (i=0; i<count[1]; i++) {
79 ioff=(j*count[1]+i)*count[2];
80 for (k=0; k<count[2]; k++)
81 image[ioff+k]=ioff+k+10;
82 }
83 }
84 #endif
85 (void) ncendef(cdf);
86 (void) miset_coords(3,0L,start);
87 (void) mivarput(cdf, img, start, count, NC_DOUBLE, NULL, image);
88
89 (void) mivarget(cdf, img, start, count, types[jtype].type,
90 types[jtype].sign, image);
91 (void) mivarput(cdf, img2, start, count, types[jtype].type,
92 types[jtype].sign, image);
93
94 (void) mivarget(cdf, img2, start, count, NC_DOUBLE, NULL, image);
95 (void) printf("Image 1 : %s %s\n",types[itype].sign,
96 types[itype].ctype);
97 (void) printf("Image 2 : %s %s\n",types[jtype].sign,
98 types[jtype].ctype);
99 for (i=0;i<count[0];i++)
100 (void) printf(" image[%d] = %g\n",(int) i, image[i]);
101 (void) miclose(cdf);
102 }
103 }
104 return(0);
105 }
106