Merge remote-tracking branch 'origin/release-v4.6.1'
[WRF.git] / tools / four2eight.c
blob222f74bce450ac35863ea521f4c743d7bf4a1e38
1 /* Jan. 2005.
3 A utility that converts unformatted binary real data files
4 to unformatted binary double precision data files.
6 Compile as
8 cc -o four2eight four2eight.c
10 If you are running this on a little-endian platform
11 compile with -DSWAP like so:
13 cc -o four2eight -DSWAP four2eight.c
15 Use as
17 four2eight < RRTM_DATA > RRTM_DATA_DBL (for example)
24 #include <stdio.h>
26 int
27 main()
29 int in, cr, cr1, n ;
30 int i ;
31 float x, x1 ;
32 double y, y1 ;
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 )
44 fread ( &x, 1, 4, stdin ) ;
45 swap4(&x,&x1) ;
46 y1 = x1 ;
47 swap8(&y1,&y) ;
48 fwrite ( &y, 1, 8, stdout ) ;
50 fread( &in, 1, 4, stdin ) ;
51 fwrite( &cr, 1, 4, stdout ) ;
53 fprintf(stderr,"\n") ;
56 void
57 swap4( a, b )
58 char a[], b[] ;
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
73 void
74 swap8( a, b )
75 char a[], b[] ;
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