Merge remote-tracking branch 'origin/release-v4.6.1'
[WRF.git] / var / external / bufr / preproc.sh
blobbc5ac7d587b447e04762527c40572b08378a1ec2
1 #!/bin/sh
3 #-------------------------------------------------------------------------------
4 # Determine the byte-ordering scheme used by the local machine.
6 cat > endiantest.c << ENDIANTEST
8 #include <stdio.h>
10 #define Order(x)\
11 fill((char *)&x, sizeof(x)); \
12 for (i=1; i<=sizeof(x); i++) { \
13 c=((x>>(byte_size*(sizeof(x)-i)))&mask); \
14 putchar(c==0 ? '?' : (char)c); \
15 } \
16 printf("\n");
18 void fill(char *p, int size) {
19 char *ab= "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
20 int i;
22 for (i=0; i<size; i++) p[i]= ab[i];
25 void endian(int byte_size) {
26 int j=0;
27 unsigned int mask, i, c;
29 mask=0;
30 for (i=1; i<=(unsigned)byte_size; i++) mask= (mask<<1)|1;
31 Order(j);
34 int cprop(void) {
35 /* Properties of type char */
36 char c;
37 int byte_size;
39 c=1; byte_size=0;
40 do { c<<=1; byte_size++; } while(c!=0);
42 return byte_size;
45 int main(void)
47 int byte_size;
49 byte_size= cprop();
50 endian(byte_size);
52 ENDIANTEST
54 $CC -o endiantest endiantest.c
56 if [ `./endiantest | cut -c1` = "A" ]
57 then
58 byte_order=BIG_ENDIAN
59 else
60 byte_order=LITTLE_ENDIAN
63 rm -f endiantest.c endiantest
66 #-------------------------------------------------------------------------------
67 # Preprocess any Fortran *.F90 files into corresponding *.f files.
69 bn=`basename $1 .for`
70 bnf=${bn}.f
71 $CPP $CPPFLAGS -D$byte_order $1 > $bnf
73 #-------------------------------------------------------------------------------