earlybrowserreborn - Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 roytam 1 /* mcidas.c:
2  *
3  * McIDAS areafile support.  contributed by Glenn P. Davis
4  * (davis@unidata.ucar.edu).
5  */
6  
7 #include "xloadimage.h"
8 #include "mcidas.h"
9  
10 char *mc_sensor();
11  
12 /*
13  * convert from little endian to big endian four byte object
14  */
15 static unsigned long
16 vhtonl(lend)
17 unsigned long lend ;
18 {
19         unsigned long bend ;
20         unsigned char *lp, *bp ;
21  
22         lp = ((unsigned char *)&lend) + 3 ;
23         bp = (unsigned char *) &bend ;
24  
25         *bp++ = *lp-- ;
26         *bp++ = *lp-- ;
27         *bp++ = *lp-- ;
28         *bp = *lp ;
29  
30         return(bend) ;
31 }
32  
33  
34 /* ARGSUSED */
35 int mcidasIdent(fullname, name)
36      char *fullname, *name;
37 { ZFILE          *zf;
38   struct area_dir dir ;
39   int             r;
40  
41   if (! (zf= zopen(fullname))) {
42     perror("mcidasIdent");
43     return(0);
44   }
45   switch (zread(zf, (byte *)&dir, sizeof(struct area_dir))) {
46   case -1:
47     perror("mcidasIdent");
48     r= 0;
49     break;
50  
51   case sizeof(struct area_dir):
52     if (dir.type != 4 && dir.type != 67108864) {
53       r= 0;
54       break;
55     }
56     r= 1;
57     break;
58  
59   default:
60     r= 0;
61     break;
62   }
63   zclose(zf);
64   return(r);
65 }
66  
67  
68 Image *mcidasLoad(fullname, name, verbose)
69      char         *fullname, *name;
70      unsigned int  verbose;
71 { ZFILE          *zf;
72   struct area_dir  dir;
73   struct navigation  nav;
74   Image          *image;
75   unsigned int    y;
76   int doswap = 0 ;
77  
78   if (! (zf= zopen(fullname))) {
79     perror("mcidasLoad");
80     return(NULL);
81   }
82   switch (zread(zf, (byte *)&dir, sizeof(struct area_dir))) {
83   case -1:
84     perror("mcidasLoad");
85     zclose(zf);
86     exit(1);
87  
88   case sizeof(struct area_dir):
89     if (dir.type != 4) {
90       if(dir.type != 67108864) {
91         zclose(zf);
92         return(NULL) ;
93       } else {
94         doswap = 1 ;
95       }
96     }
97     break;
98  
99   default:
100     zclose(zf);
101     return(NULL);
102   }
103  
104   if(doswap) {
105     unsigned long *begin ;
106     unsigned long *ulp ;
107     begin = (unsigned long *)&dir ;
108     for(ulp = begin ; ulp < &begin[AREA_COMMENTS] ; ulp++)
109        *ulp = vhtonl(*ulp) ;
110      for(ulp = &begin[AREA_CALKEY] ; ulp < &begin[AREA_STYPE] ; ulp++)
111         *ulp = vhtonl(*ulp) ;
112    }
113  
114   if (verbose)
115     (void)printf("%s %d %d (%d, %d) (%d, %d)\n",
116                  mc_sensor(dir.satid),
117                  dir.idate,
118                  dir.itime,
119                  dir.lcor,
120                  dir.ecor,
121                  dir.lres,
122                  dir.eres) ;
123   znocache(zf);
124   /* skip the nav */
125   if( zread(zf, (byte *)&nav, sizeof(struct navigation)) !=
126      sizeof(struct navigation)) {
127       zclose(zf);
128       return(NULL) ;
129   }
130  
131   /* get an image to put the data in
132    */
133  
134    image= newRGBImage(dir.esiz,
135                        dir.lsiz,
136                        8 * dir.bands);
137  
138   /* set up the colormap, linear grey scale
139    */
140  
141     for (y= 0; y < 255; y++) {
142       *(image->rgb.red + y)=
143        *(image->rgb.green + y)=
144         *(image->rgb.blue + y)= y * 257 ;
145     }
146     image->rgb.used= 255 ;
147  
148   zread(zf, image->data, dir.esiz * dir.lsiz) ;
149  
150   zclose(zf);
151   image->title= dupString(name);
152   return(image);
153 }