-
Notifications
You must be signed in to change notification settings - Fork 0
/
make_inc
executable file
·83 lines (65 loc) · 1.94 KB
/
make_inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/sh -efu
# This script creates compatable include files for
# C and Fortran languages.
# MAXN parameter for array sizes and texture structure
# is written there.
# $defs file is used to get correct order and names of structure
# fields.
defs=text1r.def
ch=text1r.h
fh=text1r.fh
struct=text1r_pars
MAXN=200
### C
# write header and MAXN parameter
cat > $ch <<EOF
/* This file is generated by $0 script.
Don't modify it! */
void text1r_init_( double *ttc, double *p, double *nu0, double *r, int *n, int *itype);
void text1r_set_vortex_cluster_( double *omega, double *omega_v);
void text1r_set_vortex_uniform_( double *omega, double *omega_v);
void text1r_set_vortex_twisted_(double *omega, double *kr);
void text1r_print_(const char *fname, int len);
void text1r_minimize_(int *msglev);
#define MAXN $MAXN
EOF
# write the structure
echo "typedef struct{" >> $ch
sed -n '
s/ARR(\([a-zA-Z0-9_]\+\))/ double \1[MAXN];/p
s/DBL(\([a-zA-Z0-9_]\+\))/ double \1;/p
s/INT(\([a-zA-Z0-9_]\+\))/ int \1;/p
' < $defs >> $ch
cat >> $ch <<EOF
} ${struct}_t;
extern ${struct}_t ${struct}_;
EOF
### Fortran
# write header and MAXN parameter
cat > $fh <<EOF
! This file is generated by $0 script.
! Don't modify it!
integer MAXN ! size of all arrays
parameter (MAXN=$MAXN)
EOF
# write structure fields
sed -n '
s|//|!|
s|/\*|!|
s|\*/||
s/ARR(\([a-zA-Z0-9_]\+\))/ real*8 text_\1(MAXN)/p
s/DBL(\([a-zA-Z0-9_]\+\))/ real*8 text_\1/p
s/INT(\([a-zA-Z0-9_]\+\))/ integer text_\1/p
' < $defs >> $fh
echo "" >> $fh
# Write common block
# 1. create a single line:
names="$(cat $defs |
sed -n 's/\(ARR\|DBL\|INT\)(\([a-zA-Z0-9_]\+\)).*/text_\2/p' |
tr '\n' ',' |
sed 's/^/common \/'$struct'\/ /; s/,$//; s/,/, /g')"
# 2. split line according to fortran rules
# (F90 and F77 compatibility: & at 5 and 73 columns)
echo $names | fold -s -w 64 |
while read l; do printf "%6s %-65s&\n" '&' "$l"; done |
sed '1s/&/ /; $s/ *&$//' >> $fh