3 |
michaesp |
1 |
PROGRAM rot2geo
|
|
|
2 |
|
|
|
3 |
c ***********************************************************************
|
|
|
4 |
c * Rotate lat/lon coordinates *
|
|
|
5 |
c * Michael Sprenger / Spring, summer 2010 *
|
|
|
6 |
c ***********************************************************************
|
|
|
7 |
|
|
|
8 |
implicit none
|
|
|
9 |
|
|
|
10 |
c ----------------------------------------------------------------------
|
|
|
11 |
c Declaration of variables
|
|
|
12 |
c ----------------------------------------------------------------------
|
|
|
13 |
|
|
|
14 |
c Mode for geo2rot
|
|
|
15 |
character*80 mode
|
|
|
16 |
|
|
|
17 |
c Input and output format for trajectories (see iotra.f)
|
|
|
18 |
character*80 inpfile ! Input filename
|
|
|
19 |
character*80 outfile ! Output filename
|
|
|
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 (:,:,:) :: tra ! Trajectories (ntra,ntim,ncol)
|
|
|
26 |
character*80 vars(100) ! Variable names
|
|
|
27 |
integer refdate(6) ! Reference date
|
|
|
28 |
|
|
|
29 |
c Pole position
|
|
|
30 |
real pollon ! Rotated pole longitude
|
|
|
31 |
real pollat ! Rotated pole latitude
|
|
|
32 |
|
|
|
33 |
c Auxiliary variables
|
|
|
34 |
integer inpmode
|
|
|
35 |
integer outmode
|
|
|
36 |
integer stat
|
|
|
37 |
integer fid
|
|
|
38 |
integer i,j,k
|
|
|
39 |
real lat,lon,rlat,rlon
|
|
|
40 |
|
|
|
41 |
c Numerical epsilon
|
|
|
42 |
real eps
|
|
|
43 |
parameter (eps=0.0001)
|
|
|
44 |
|
|
|
45 |
c Externals
|
|
|
46 |
real lmtolms
|
|
|
47 |
real phtophs
|
|
|
48 |
real lmstolm
|
|
|
49 |
real phstoph
|
|
|
50 |
external lmtolms,phtophs
|
|
|
51 |
external lmstolm,phstoph
|
|
|
52 |
|
|
|
53 |
c ----------------------------------------------------------------------
|
|
|
54 |
c Read parameters
|
|
|
55 |
c ----------------------------------------------------------------------
|
|
|
56 |
|
|
|
57 |
c Read parameters
|
|
|
58 |
open(10,file='rot2geo.param')
|
|
|
59 |
read(10,*) mode
|
|
|
60 |
|
|
|
61 |
if ( mode.eq.'trajectory' ) then
|
|
|
62 |
read(10,*) inpfile
|
|
|
63 |
read(10,*) outfile
|
|
|
64 |
read(10,*) ntra,ntim,ncol
|
|
|
65 |
|
|
|
66 |
elseif ( mode.eq.'position' ) then
|
|
|
67 |
read(10,*) rlon
|
|
|
68 |
read(10,*) rlat
|
|
|
69 |
|
|
|
70 |
endif
|
|
|
71 |
|
|
|
72 |
read(10,*) pollon,pollat
|
|
|
73 |
|
|
|
74 |
close(10)
|
|
|
75 |
|
|
|
76 |
c ----------------------------------------------------------------------
|
|
|
77 |
c Rotate a single position
|
|
|
78 |
c ----------------------------------------------------------------------
|
|
|
79 |
|
|
|
80 |
if ( mode.ne.'position') goto 100
|
|
|
81 |
|
|
|
82 |
if ( abs(pollat-90.).gt.eps) then
|
|
|
83 |
lon = lmstolm(rlat,rlon,pollat,pollon)
|
|
|
84 |
lat = phstoph(rlat,rlon,pollat,pollon)
|
|
|
85 |
else
|
|
|
86 |
lon = rlon
|
|
|
87 |
lat = rlat
|
|
|
88 |
endif
|
|
|
89 |
|
|
|
90 |
print*,lon,lat
|
|
|
91 |
|
|
|
92 |
100 continue
|
|
|
93 |
|
|
|
94 |
c ----------------------------------------------------------------------
|
|
|
95 |
c Rotate a trajectory file
|
|
|
96 |
c ----------------------------------------------------------------------
|
|
|
97 |
|
|
|
98 |
if ( mode.ne.'trajectory') goto 200
|
|
|
99 |
|
|
|
100 |
c Determine the formats
|
|
|
101 |
call mode_tra(inpmode,inpfile)
|
|
|
102 |
if (inpmode.eq.-1) inpmode=1
|
|
|
103 |
call mode_tra(outmode,outfile)
|
|
|
104 |
if (outmode.eq.-1) outmode=1
|
|
|
105 |
|
|
|
106 |
c Allocate memory
|
|
|
107 |
allocate(tra(ntra,ntim,ncol),stat=stat)
|
|
|
108 |
if (stat.ne.0) print*,'*** error allocating array tra ***'
|
|
|
109 |
|
|
|
110 |
c Read inpufile
|
|
|
111 |
call ropen_tra(fid,inpfile,ntra,ntim,ncol,refdate,vars,inpmode)
|
|
|
112 |
call read_tra (fid,tra,ntra,ntim,ncol,inpmode)
|
|
|
113 |
call close_tra(fid,inpmode)
|
|
|
114 |
|
|
|
115 |
c Do the coordinate rotation
|
|
|
116 |
do i=1,ntra
|
|
|
117 |
do j=1,ntim
|
|
|
118 |
|
|
|
119 |
rlon = tra(i,j,2)
|
|
|
120 |
rlat = tra(i,j,3)
|
|
|
121 |
|
|
|
122 |
if ( abs(pollat-90.).gt.eps) then
|
|
|
123 |
lon = lmstolm(rlat,rlon,pollat,pollon)
|
|
|
124 |
lat = phstoph(rlat,rlon,pollat,pollon)
|
|
|
125 |
else
|
|
|
126 |
lon = rlon
|
|
|
127 |
lat = rlat
|
|
|
128 |
endif
|
|
|
129 |
|
|
|
130 |
tra(i,j,2) = lon
|
|
|
131 |
tra(i,j,3) = lat
|
|
|
132 |
|
|
|
133 |
enddo
|
|
|
134 |
enddo
|
|
|
135 |
|
|
|
136 |
c Write output file
|
|
|
137 |
call wopen_tra(fid,outfile,ntra,ntim,ncol,refdate,vars,outmode)
|
|
|
138 |
call write_tra(fid,tra,ntra,ntim,ncol,outmode)
|
|
|
139 |
call close_tra(fid,outmode)
|
|
|
140 |
|
|
|
141 |
200 continue
|
|
|
142 |
|
|
|
143 |
end
|
|
|
144 |
|
|
|
145 |
|
|
|
146 |
|
|
|
147 |
|