Last change
on this file since 1 was
1,
checked in by lfita, 10 years ago
|
- -- --- Opening of the WRF+LMDZ coupling repository --- -- -
WRF: version v3.3
LMDZ: version v1818
More details in:
|
File size:
1.5 KB
|
Line | |
---|
1 | #include <stdio.h> |
---|
2 | #include <stdlib.h> |
---|
3 | #include <stddef.h> |
---|
4 | #include "grib.h" |
---|
5 | |
---|
6 | |
---|
7 | /* wesley ebisuzaki v1.3 |
---|
8 | * |
---|
9 | * write ieee file -- big endian format |
---|
10 | * |
---|
11 | * input float *array data to be written |
---|
12 | * int n size of array |
---|
13 | * int header 1 for f77 style header 0 for none |
---|
14 | * (header is 4 byte header |
---|
15 | * FILE *output output file |
---|
16 | * |
---|
17 | * v1.2 7/97 buffered, faster |
---|
18 | * v1.3 2/99 fixed (typo) error in wrtieee_header found by |
---|
19 | * Bob Farquhar |
---|
20 | */ |
---|
21 | |
---|
22 | #define BSIZ 1024*4 |
---|
23 | |
---|
24 | int wrtieee(float *array, int n, int header, FILE *output) { |
---|
25 | |
---|
26 | unsigned long int l; |
---|
27 | int i, nbuf; |
---|
28 | unsigned char buff[BSIZ]; |
---|
29 | unsigned char h4[4]; |
---|
30 | |
---|
31 | nbuf = 0; |
---|
32 | if (header) { |
---|
33 | l = n * 4; |
---|
34 | for (i = 0; i < 4; i++) { |
---|
35 | h4[i] = l & 255; |
---|
36 | l >>= 8; |
---|
37 | } |
---|
38 | buff[nbuf++] = h4[3]; |
---|
39 | buff[nbuf++] = h4[2]; |
---|
40 | buff[nbuf++] = h4[1]; |
---|
41 | buff[nbuf++] = h4[0]; |
---|
42 | } |
---|
43 | for (i = 0; i < n; i++) { |
---|
44 | if (nbuf >= BSIZ) { |
---|
45 | fwrite(buff, 1, BSIZ, output); |
---|
46 | nbuf = 0; |
---|
47 | } |
---|
48 | flt2ieee(array[i], buff + nbuf); |
---|
49 | nbuf += 4; |
---|
50 | } |
---|
51 | if (header) { |
---|
52 | if (nbuf == BSIZ) { |
---|
53 | fwrite(buff, 1, BSIZ, output); |
---|
54 | nbuf = 0; |
---|
55 | } |
---|
56 | buff[nbuf++] = h4[3]; |
---|
57 | buff[nbuf++] = h4[2]; |
---|
58 | buff[nbuf++] = h4[1]; |
---|
59 | buff[nbuf++] = h4[0]; |
---|
60 | } |
---|
61 | if (nbuf) fwrite(buff, 1, nbuf, output); |
---|
62 | return 0; |
---|
63 | } |
---|
64 | |
---|
65 | /* write a big-endian 4 byte integer .. f77 IEEE header */ |
---|
66 | |
---|
67 | int wrtieee_header(unsigned int n, FILE *output) { |
---|
68 | unsigned h4[4]; |
---|
69 | |
---|
70 | h4[0] = n & 255; |
---|
71 | h4[1] = (n >> 8) & 255; |
---|
72 | h4[2] = (n >> 16) & 255; |
---|
73 | h4[3] = (n >> 24) & 255; |
---|
74 | |
---|
75 | putc(h4[3],output); |
---|
76 | putc(h4[2],output); |
---|
77 | putc(h4[1],output); |
---|
78 | putc(h4[0],output); |
---|
79 | |
---|
80 | return 0; |
---|
81 | } |
---|
82 | |
---|
Note: See
TracBrowser
for help on using the repository browser.