Last change
on this file since 3094 was
2759,
checked in by aslmd, 2 years ago
|
adding unmodified code from WRFV3.0.1.1, expurged from useless data +1M size
|
File size:
1.5 KB
|
Rev | Line | |
---|
[2759] | 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 | main() |
---|
| 27 | { |
---|
| 28 | int in, cr, cr1, n ; |
---|
| 29 | int i ; |
---|
| 30 | float x, x1 ; |
---|
| 31 | double y, y1 ; |
---|
| 32 | |
---|
| 33 | while ( |
---|
| 34 | fread( &in, 1, 4, stdin ) > 0 ) { |
---|
| 35 | swap4(&in, &cr) ; |
---|
| 36 | n = cr ; |
---|
| 37 | cr1 = 2*cr ; |
---|
| 38 | fprintf(stderr, "%d > %d\n",cr,cr1) ; |
---|
| 39 | swap4(&cr1,&cr) ; |
---|
| 40 | fwrite( &cr, 1, 4, stdout ) ; |
---|
| 41 | for ( i = 0 ; i < n ; i += 4 ) |
---|
| 42 | { |
---|
| 43 | fread ( &x, 1, 4, stdin ) ; |
---|
| 44 | swap4(&x,&x1) ; |
---|
| 45 | y1 = x1 ; |
---|
| 46 | swap8(&y1,&y) ; |
---|
| 47 | fwrite ( &y, 1, 8, stdout ) ; |
---|
| 48 | } |
---|
| 49 | fread( &in, 1, 4, stdin ) ; |
---|
| 50 | fwrite( &cr, 1, 4, stdout ) ; |
---|
| 51 | } |
---|
| 52 | fprintf(stderr,"\n") ; |
---|
| 53 | } |
---|
| 54 | |
---|
| 55 | swap4( a, b ) |
---|
| 56 | char a[], b[] ; |
---|
| 57 | { |
---|
| 58 | #ifdef SWAP |
---|
| 59 | b[0] = a[3] ; |
---|
| 60 | b[1] = a[2] ; |
---|
| 61 | b[2] = a[1] ; |
---|
| 62 | b[3] = a[0] ; |
---|
| 63 | #else |
---|
| 64 | b[0] = a[0] ; |
---|
| 65 | b[1] = a[1] ; |
---|
| 66 | b[2] = a[2] ; |
---|
| 67 | b[3] = a[3] ; |
---|
| 68 | #endif |
---|
| 69 | } |
---|
| 70 | |
---|
| 71 | swap8( a, b ) |
---|
| 72 | char a[], b[] ; |
---|
| 73 | { |
---|
| 74 | #ifdef SWAP |
---|
| 75 | b[0] = a[7] ; |
---|
| 76 | b[1] = a[6] ; |
---|
| 77 | b[2] = a[5] ; |
---|
| 78 | b[3] = a[4] ; |
---|
| 79 | b[4] = a[3] ; |
---|
| 80 | b[5] = a[2] ; |
---|
| 81 | b[6] = a[1] ; |
---|
| 82 | b[7] = a[0] ; |
---|
| 83 | #else |
---|
| 84 | b[0] = a[0] ; |
---|
| 85 | b[1] = a[1] ; |
---|
| 86 | b[2] = a[2] ; |
---|
| 87 | b[3] = a[3] ; |
---|
| 88 | b[4] = a[4] ; |
---|
| 89 | b[5] = a[5] ; |
---|
| 90 | b[6] = a[6] ; |
---|
| 91 | b[7] = a[7] ; |
---|
| 92 | #endif |
---|
| 93 | } |
---|
| 94 | |
---|
Note: See
TracBrowser
for help on using the repository browser.