Subversion Repositories lagranto.arpege

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 michaesp 1
      PROGRAM tracal
2
 
3
c     ***********************************************************************
4
c     * Calculations with trajectories                                      *
5
c     * Michael Sprenger / Spring, summer 2010                              *
6
c     ***********************************************************************
7
 
8
      use evaluate
9
 
10
      implicit none
11
 
12
c     ----------------------------------------------------------------------
13
c     Declaration of variables
14
c     ----------------------------------------------------------------------
15
 
16
c     Input and output format for trajectories (see iotra.f)
17
      character*80                           inpfile     ! Input filename
18
      character*80                           outfile     ! Output filename
19
      character*80                           expr        ! Expression for calculation
20
 
21
c     Trajectories
22
      integer                                ntra        ! Number of trajectories
23
      integer                                ntim        ! Number of times
24
      integer                                ncol        ! Number of columns
25
      real,allocatable, dimension (:,:,:) :: trainp      ! Trajectories (ntra,ntim,ncol  )
26
      real,allocatable, dimension (:,:,:) :: traout      ! Trajectories (ntra,ntim,ncol+1)
27
      character*80                           vars(100)   ! Variable names
28
      integer                                refdate(6)  ! Reference date
29
 
30
c     Auxiliary variables
31
      integer                                inpmode
32
      integer                                outmode
33
      integer                                stat
34
      integer                                fid
35
      integer                                i,j,k
36
      character (len=24)                     col,new
37
      real                                   value
38
      character                              ch
39
      integer                                ileft,iright
40
 
41
c     ----------------------------------------------------------------------
42
c     Do the reformating
43
c     ----------------------------------------------------------------------
44
 
45
c     Read parameters
46
      open(10,file='tracal.param')
47
       read(10,*) inpfile
48
       read(10,*) outfile
49
       read(10,*) expr
50
       read(10,*) ntra,ntim,ncol
51
      close(10)
52
 
53
c	  Get the name of the output field
54
	  ileft  = 1
55
	  iright = 0
56
	  do i=1,80
57
	  	if ( expr(i:i).eq.'=' ) iright = i
58
	  enddo
59
	  if ( iright.eq.0 ) then
60
	      vars(ncol+1) = 'CALC'
61
	      expr = 'CALC='//trim(expr)
62
	  else
63
	      vars(ncol+1) = trim( expr(1:iright-1) )
64
	  endif
65
	  new = vars( ncol+1 )
66
 
67
      print*,'inp  = ',trim(inpfile)
68
      print*,'out  = ',trim(outfile)
69
      print*,'expr = ',trim(expr),' ---> ',trim( new )
70
 
71
c     Determine the formats
72
      call mode_tra(inpmode,inpfile)
73
      if (inpmode.eq.-1) inpmode=1
74
      call mode_tra(outmode,outfile)
75
      if (outmode.eq.-1) outmode=1
76
 
77
c     Allocate memory
78
      allocate(trainp(ntra,ntim,ncol),stat=stat)
79
      if (stat.ne.0) print*,'*** error allocating array trainp   ***'
80
      allocate(traout(ntra,ntim,ncol+1),stat=stat)
81
      if (stat.ne.0) print*,'*** error allocating array traout   ***'
82
 
83
c     Read inpufile
84
      call ropen_tra(fid,inpfile,ntra,ntim,ncol,refdate,vars,inpmode)
85
      call read_tra (fid,trainp,ntra,ntim,ncol,inpmode)
86
      call close_tra(fid,inpmode)
87
 
88
c	  Copy to output trajectory
89
	  do i=1,ntra
90
	  	do j=1,ntim
91
	  	  do k=1,ncol
92
	  	     traout(i,j,k) = trainp(i,j,k)
93
	  	  enddo
94
	  	enddo
95
      enddo
96
 
97
c	  Loop over all trajectories
98
	  do i=1,ntra
99
	  	do j=1,ntim
100
	  		do k=1,ncol
101
 
102
c	          Attribute trajectory values to symbols
103
	          col = vars(k)
104
 	  		  call defparam( col, traout(i,j,k) )
105
 
106
	  		enddo
107
 
108
c	        Evaluate expression
109
	        call evaleqn(expr)
110
 
111
c	        Get the result
112
	        call getparam(new,value)
113
	        traout(i,j,ncol+1) = value
114
 
115
	    enddo
116
	  enddo
117
 
118
c     Write output file
119
      call wopen_tra(fid,outfile,ntra,ntim,ncol+1,refdate,vars,outmode)
120
      call write_tra(fid,traout,ntra,ntim,ncol+1,outmode)
121
      call close_tra(fid,outmode)
122
 
123
      end
124
 
125
 
126
 
127