source: codes/icosagcm/devel/Python/codegen @ 919

Last change on this file since 919 was 852, checked in by dubos, 5 years ago

devel : moved DYSL for compute_pvort_only into compute_pvort_only.F90

  • Property svn:executable set to *
File size: 1.7 KB
Line 
1#!/bin/bash
2
3function filter()
4{
5    PASS=$1 ; shift
6    cpp -P -DPASS_$PASS $* -include ../macros.jin
7}
8
9function log()
10{
11    echo $*
12    $*
13}
14
15function extract_dysl()
16{
17    sed -n '/BEGIN_DYSL/,/END_DYSL/{//b;p}' compute_pvort_only.F90
18}
19
20function main()
21{
22    VARIANT=$SRCDIR/$1
23    cd $VARIANT
24    rm -f *~ tmp/*
25    mkdir -p tmp
26    cd tmp
27    cp $SRCDIR/macros.jin . # jinja macros common to all variants
28    cpp -P -DPASS_JINJA ../macros.jin >> macros.jin # variant-specific macros
29
30    # first expand user-defined CPP and jinja macros
31    cat $SRCDIR/kernels_*.jin | cpp -P > caldyn_all.jin
32    $PYTHON -u $ROOT/jinja caldyn_all.jin > caldyn_all.dysl
33    # then expand the code-generating CPP and jinja macros
34    cat caldyn_all.dysl | filter PRE1 | filter PRE2 >> macros.jin
35    $PYTHON -u $ROOT/jinja macros.jin > caldyn_all.k90
36    # extract each kernel and apply post-jinja CPP macros
37    KERNELS=$(grep KERNEL caldyn_all.dysl | cpp -P -D'KERNEL(x)=x')
38    for NAME in $KERNELS ; do
39        cat caldyn_all.k90 | filter POST1 -DKERNEL_${NAME} | filter POST2 | sed '/^$/d' > ../${NAME}.k90
40        head ../${NAME}.k90
41    done
42
43    cd ..
44    grep ERROR *.k90
45
46    cd $VARIANT
47    wc *.k90
48    cd $ROOT
49}
50
51if [ -z "$CODEGEN_ENV_SET" ] ; then
52    cat <<EOF
53Before running this script, you must source one of the *.env scripts found in the env/ directory.
54This will set up appropriate, machine-dependent values for the following environment variables :
55PYTHON F90 C99 CFLAGS FFLAGS LINK SOFLAGS LDFLAGS LIBS ...
56EOF
57else
58    set +x
59   
60    ROOT=$PWD
61    LIBDIR=$ROOT/lib
62    SRCDIR=$ROOT/src
63    cd $SRCDIR
64    grep FIXME *.jin
65
66    for x in $* ; do
67        echo "Generating code for variant : $x"
68        main $x
69    done
70fi
Note: See TracBrowser for help on using the repository browser.