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 | /* Jan. 2005. |
---|
2 | |
---|
3 | A utility that converts unformatted binary real data files |
---|
4 | to unformatted binary double precision data files. |
---|
5 | |
---|
6 | Compile as |
---|
7 | |
---|
8 | cc -o four2eight four2eight.c |
---|
9 | |
---|
10 | If you are running this on a little-endian platform |
---|
11 | compile with -DSWAP like so: |
---|
12 | |
---|
13 | cc -o four2eight -DSWAP four2eight.c |
---|
14 | |
---|
15 | Use as |
---|
16 | |
---|
17 | four2eight < RRTM_DATA > RRTM_DATA_DBL (for example) |
---|
18 | |
---|
19 | JM |
---|
20 | |
---|
21 | */ |
---|
22 | |
---|
23 | |
---|
24 | #include <stdio.h> |
---|
25 | |
---|
26 | int |
---|
27 | main() |
---|
28 | { |
---|
29 | int in, cr, cr1, n ; |
---|
30 | int i ; |
---|
31 | float x, x1 ; |
---|
32 | double y, y1 ; |
---|
33 | |
---|
34 | while ( |
---|
35 | fread( &in, 1, 4, stdin ) > 0 ) { |
---|
36 | swap4(&in, &cr) ; |
---|
37 | n = cr ; |
---|
38 | cr1 = 2*cr ; |
---|
39 | fprintf(stderr, "%d > %d\n",cr,cr1) ; |
---|
40 | swap4(&cr1,&cr) ; |
---|
41 | fwrite( &cr, 1, 4, stdout ) ; |
---|
42 | for ( i = 0 ; i < n ; i += 4 ) |
---|
43 | { |
---|
44 | fread ( &x, 1, 4, stdin ) ; |
---|
45 | swap4(&x,&x1) ; |
---|
46 | y1 = x1 ; |
---|
47 | swap8(&y1,&y) ; |
---|
48 | fwrite ( &y, 1, 8, stdout ) ; |
---|
49 | } |
---|
50 | fread( &in, 1, 4, stdin ) ; |
---|
51 | fwrite( &cr, 1, 4, stdout ) ; |
---|
52 | } |
---|
53 | fprintf(stderr,"\n") ; |
---|
54 | } |
---|
55 | |
---|
56 | void |
---|
57 | swap4( a, b ) |
---|
58 | char a[], b[] ; |
---|
59 | { |
---|
60 | #ifdef SWAP |
---|
61 | b[0] = a[3] ; |
---|
62 | b[1] = a[2] ; |
---|
63 | b[2] = a[1] ; |
---|
64 | b[3] = a[0] ; |
---|
65 | #else |
---|
66 | b[0] = a[0] ; |
---|
67 | b[1] = a[1] ; |
---|
68 | b[2] = a[2] ; |
---|
69 | b[3] = a[3] ; |
---|
70 | #endif |
---|
71 | } |
---|
72 | |
---|
73 | void |
---|
74 | swap8( a, b ) |
---|
75 | char a[], b[] ; |
---|
76 | { |
---|
77 | #ifdef SWAP |
---|
78 | b[0] = a[7] ; |
---|
79 | b[1] = a[6] ; |
---|
80 | b[2] = a[5] ; |
---|
81 | b[3] = a[4] ; |
---|
82 | b[4] = a[3] ; |
---|
83 | b[5] = a[2] ; |
---|
84 | b[6] = a[1] ; |
---|
85 | b[7] = a[0] ; |
---|
86 | #else |
---|
87 | b[0] = a[0] ; |
---|
88 | b[1] = a[1] ; |
---|
89 | b[2] = a[2] ; |
---|
90 | b[3] = a[3] ; |
---|
91 | b[4] = a[4] ; |
---|
92 | b[5] = a[5] ; |
---|
93 | b[6] = a[6] ; |
---|
94 | b[7] = a[7] ; |
---|
95 | #endif |
---|
96 | } |
---|
97 | |
---|
Note: See
TracBrowser
for help on using the repository browser.