source: LMDZ6/branches/LMDZ_ECRad/libf/phylmd/ecrad/bin/make_intfbl.1.pl @ 5444

Last change on this file since 5444 was 4728, checked in by idelkadi, 15 months ago

Update of ecrad in the LMDZ_ECRad branch of LMDZ:

  • version 1.6.1 of ecrad
  • files are no longer grouped in the same ecrad directory.
  • the structure of ecrad offline is preserved to facilitate updating in LMDZ
  • cfg.bld modified to take into account the new added subdirectories.
  • the interface routines and those added in ecrad are moved to the phylmd directory
  • Property svn:executable set to *
File size: 4.0 KB
Line 
1#!/usr/bin/perl
2#!/usr/local/apps/perl/current/bin/perl
3#
4# (C) Copyright 2010- ECMWF.
5#
6# This software is licensed under the terms of the Apache Licence Version 2.0
7# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
8#
9# In applying this licence, ECMWF does not waive the privileges and immunities
10# granted to it by virtue of its status as an intergovernmental organisation
11# nor does it submit to any jurisdiction.
12
13# Modified to cope with rttov files which have built in interface
14# blocks that just need to be parsed out.
15# Paul Burton 2010
16
17use strict;
18use warnings;
19#use lib "/home/rd/rdx/bin/prepifs/perl";
20use Fortran90_stuff;
21use Data::Dumper;
22$Data::Dumper::Indent = 1;
23
24my $rttov_intf=0;
25
26{
27  my (@files);
28  (@files) = @ARGV;
29  &setup_parse();
30  my $locintfbldir=$ENV{LOC_INTFBDIR} or die "LOC_INTFBDIR not defined ";
31  my $intfbldir=$ENV{INTFBDIR} or die "INTFBDIR not defined ";
32  our $study_called;
33  FILE:for (@files) {
34    my (@interface_block);
35    my (@line_hash);
36    chomp;
37 # Read in lines from file
38    my $fname = $_;
39
40    my $int_block_fname=$fname;
41    $int_block_fname=~s/\.F90/.intfb.h/;
42    $int_block_fname=~s#.*/(.+)$#$1#;
43    my $ofname=$intfbldir.'/'.$int_block_fname;
44    my $nfname=$locintfbldir.'/'.$int_block_fname;
45   
46# Do nothing if file hasn't changed since intfb already created
47
48    if ( (-f $nfname) &&
49         ( (stat($nfname))[9] > (stat($fname))[9] )) {
50      print "INTERFACE BLOCK $int_block_fname UP TO DATE\n";
51      next FILE;
52    }
53
54# skip .h files, Nils
55    my $base = $_;
56    ( $base = $fname ) =~ s/\.(\w+)\s*$//;
57    my $suffix = $1;
58    next if ( $suffix eq "h" );
59# end Nils
60    my @statements=();
61    my %prog_info=();
62    my @lines = &readfile($fname);
63
64    $rttov_intf=0;
65    if ($fname=~/^satrad\//) {
66      if (grep(/^!INTF_END/,@lines)) {
67        print "Working on rttov file $fname\n";
68        $rttov_intf=1;
69        &create_rttov_interface_block(\@lines,\@interface_block,\%prog_info);
70      } else {
71        # satrad file without INTF_END marker - ignore
72        print "Ignoring satrad file $fname (no INTF_END marker)\n";
73        next;
74      }
75    } else {
76      print "Working on file $fname\n";
77      &expcont(\@lines,\@statements);
78      $study_called=0;
79      &study(\@statements,\%prog_info);
80#     print Dumper(\%prog_info);
81    }
82    unless($prog_info{is_module}) {
83      if ($rttov_intf) {
84        @lines=@interface_block;
85      } else {
86        &create_interface_block(\@statements,\@interface_block);
87        &cont_lines(\@interface_block,\@lines,\@line_hash);
88      }
89      if ( -f $nfname ) {
90        my @nldlines=&readfile($nfname);
91        if(&eq_array(\@nldlines, \@lines)){
92          print "INTERFACE BLOCK $int_block_fname NOT UPDATED \n" ;
93          next FILE;
94        }
95      }
96      if ( -f $ofname ) {
97        my @oldlines=&readfile($ofname);
98        if(&eq_array(\@oldlines, \@lines)){
99          print "INTERFACE BLOCK $int_block_fname UNCHANGED \n" ;
100          next FILE;
101        }
102      }
103      print "WRITE INTERFACE BLOCK $int_block_fname \n";
104      print "$nfname \n";
105      &writefile($nfname,\@lines);
106    }
107  }
108}
109sub eq_array {
110    my ($ra, $rb) = @_;
111    return 0 unless $#$ra == $#$rb;
112    for my $i (0..$#$ra) {
113        return 0 unless $ra->[$i] eq $rb->[$i];
114    }
115    return 1;
116}
117
118sub create_rttov_interface_block {
119  my ($lines,$intfblk,$prog_info)=(@_);
120  my ($line,$on,$what,@intf);
121  $on=1;
122  $what="";
123  for $line (@{$lines}) {
124    $on=1 if ($line=~/^\s*!\s*INTF_ON\s*$/);
125    $on=0 if ($line=~/^\s*!\s*INTF_OFF\s*$/);
126    last if ($line=~/^\s*!INTF_END\s*$/);
127    if ($what eq "") {
128      $what="SUBROUTINE" if ($line=~/^\s*SUBROUTINE/i);
129      $what="FUNCTION" if ($line=~/\s*FUNCTION/i);
130      $what="MODULE" if ($line=~/^\s*MODULE/i);
131      $what="PROGRAM" if ($line=~/^\s*PROGRAM/i);
132    }
133    next if ($line=~/^\s*!/ || $line=~/^\s*$/ || !$on );
134    push(@intf,$line);
135  }
136  die "Cannot guess if file contains a SUBROUTINE or FUNCTION.\n" unless $what;
137  $prog_info->{is_module}=1 if ($what eq "MODULE");
138  @{$intfblk}=("INTERFACE\n",@intf,"END $what\n","END INTERFACE\n");
139}
140   
Note: See TracBrowser for help on using the repository browser.