1 | !********************************************************************** |
---|
2 | ! Copyright 1998,1999,2000,2001,2002,2005,2007,2008,2009,2010 * |
---|
3 | ! Andreas Stohl, Petra Seibert, A. Frank, Gerhard Wotawa, * |
---|
4 | ! Caroline Forster, Sabine Eckhardt, John Burkhart, Harald Sodemann * |
---|
5 | ! * |
---|
6 | ! This file is part of FLEXPART. * |
---|
7 | ! * |
---|
8 | ! FLEXPART is free software: you can redistribute it and/or modify * |
---|
9 | ! it under the terms of the GNU General Public License as published by* |
---|
10 | ! the Free Software Foundation, either version 3 of the License, or * |
---|
11 | ! (at your option) any later version. * |
---|
12 | ! * |
---|
13 | ! FLEXPART is distributed in the hope that it will be useful, * |
---|
14 | ! but WITHOUT ANY WARRANTY; without even the implied warranty of * |
---|
15 | ! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
---|
16 | ! GNU General Public License for more details. * |
---|
17 | ! * |
---|
18 | ! You should have received a copy of the GNU General Public License * |
---|
19 | ! along with FLEXPART. If not, see <http://www.gnu.org/licenses/>. * |
---|
20 | !********************************************************************** |
---|
21 | |
---|
22 | program grib2flexpart |
---|
23 | |
---|
24 | !***************************************************************************** |
---|
25 | ! * |
---|
26 | ! This is the GRIB 2 FP conversion routine * |
---|
27 | ! * |
---|
28 | ! Author: M. Harustak * |
---|
29 | ! * |
---|
30 | ! 05 October 2015 * |
---|
31 | ! * |
---|
32 | !***************************************************************************** |
---|
33 | ! * |
---|
34 | ! Variables: * |
---|
35 | ! * |
---|
36 | ! Constants: * |
---|
37 | ! * |
---|
38 | !***************************************************************************** |
---|
39 | |
---|
40 | use point_mod |
---|
41 | use par_mod |
---|
42 | use com_mod |
---|
43 | use conv_mod |
---|
44 | |
---|
45 | implicit none |
---|
46 | |
---|
47 | integer :: metdata_format = unknown_metdata |
---|
48 | integer :: itime, nstop1 |
---|
49 | integer :: i |
---|
50 | character(len=256) :: arg |
---|
51 | character(len=512) :: dumpPath |
---|
52 | character(len=512) :: inputFileName |
---|
53 | character(len=512) :: nestedFileName |
---|
54 | character(len=32) :: lsubgridTXT |
---|
55 | integer :: useAvailable = 0 |
---|
56 | |
---|
57 | ! Print the GPL License statement |
---|
58 | !******************************************************* |
---|
59 | print*,'Welcome to GRIB2FLEXPART Version 1.0' |
---|
60 | print*,'FLEXPART is free software released under the GNU Genera'// & |
---|
61 | 'l Public License.' |
---|
62 | |
---|
63 | ! no argument => error |
---|
64 | if (( iargc().lt.2 ).or.( iargc().eq.3)) then |
---|
65 | print *,' ' |
---|
66 | print *,'Usage in use-available mode: grib2flexpart useAvailable <output directory>' |
---|
67 | print *,'Usage in command line mode: grib2flexpart forward|backward subgrid <output directory> <source file> [<source file>...]' |
---|
68 | print *,' ' |
---|
69 | stop 'Error: Missing arguments' |
---|
70 | elseif ( iargc().eq.2 ) then |
---|
71 | call getarg(1,arg) |
---|
72 | if ( arg.eq."useAvailable" ) then |
---|
73 | print *,'Running in use-available mode' |
---|
74 | useAvailable = 1 |
---|
75 | else |
---|
76 | print *,' ' |
---|
77 | print *,'Usage in use-available mode: grib2flexpart useAvailable <output directory>' |
---|
78 | print *,'Usage in command line mode: grib2flexpart forward|backward subgrid <output directory> & |
---|
79 | <source file> [<source file>...]' |
---|
80 | print *,' ' |
---|
81 | stop 'Error: Incorrect arguments' |
---|
82 | endif |
---|
83 | else |
---|
84 | ! 2 and more arguments => ok, parse arguments |
---|
85 | call getarg(1,arg) |
---|
86 | if ( arg.eq."forward") then |
---|
87 | ldirect = 1 |
---|
88 | else if ( arg.eq."backward") then |
---|
89 | ldirect = -1 |
---|
90 | else |
---|
91 | print *,' ' |
---|
92 | print *,'Usage in use-available mode: grib2flexpart useAvailable <output directory>' |
---|
93 | print *,'Usage in command line mode: grib2flexpart forward|backward subgrid <output directory> & |
---|
94 | <source file> [<source file>...]' |
---|
95 | print *,' ' |
---|
96 | stop 'Error: Incorrect arguments' |
---|
97 | endif |
---|
98 | print *,'Running in command line mode' |
---|
99 | useAvailable = 0 |
---|
100 | endif |
---|
101 | |
---|
102 | if ( useAvailable.eq.0 ) then |
---|
103 | call getarg(2,lsubgridTxt) |
---|
104 | read (lsubgridTxt, '(i10)') lsubgrid |
---|
105 | lsubgrid=1 |
---|
106 | call getarg(3,dumpPath) |
---|
107 | do i=4,iargc() |
---|
108 | call getarg(i,inputFileName) |
---|
109 | numbwf = i - 4 + 1 |
---|
110 | if ( ldirect.eq.1 ) then |
---|
111 | wfname(i-4+1) = inputFileName |
---|
112 | else |
---|
113 | wfname(iargc()+1-i) = inputFileName |
---|
114 | endif |
---|
115 | end do |
---|
116 | |
---|
117 | else |
---|
118 | call getarg(2,dumpPath) |
---|
119 | |
---|
120 | call readpaths |
---|
121 | |
---|
122 | call readcommand |
---|
123 | |
---|
124 | call readavailable |
---|
125 | endif |
---|
126 | |
---|
127 | ! Reset the times of the wind fields that are kept in memory to no time |
---|
128 | !********************************************************************** |
---|
129 | |
---|
130 | do i=1,2 |
---|
131 | memind(i)=i |
---|
132 | memtime(i)=999999999 |
---|
133 | end do |
---|
134 | |
---|
135 | ! Detect metdata format |
---|
136 | call detectformat(metdata_format) |
---|
137 | if (metdata_format.eq.ecmwf_metdata) then |
---|
138 | print*,'ECMWF metdata detected' |
---|
139 | elseif (metdata_format.eq.gfs_metdata) then |
---|
140 | print*,'NCEP metdata detected' |
---|
141 | else |
---|
142 | stop 'Unknown metdata format' |
---|
143 | endif |
---|
144 | |
---|
145 | ! Read the model grid specifications, |
---|
146 | ! both for the mother domain and eventual nests |
---|
147 | !********************************************** |
---|
148 | |
---|
149 | if (metdata_format.eq.ecmwf_metdata) call gridcheck_ecmwf |
---|
150 | if (metdata_format.eq.gfs_metdata) call gridcheck_gfs |
---|
151 | call gridcheck_nests |
---|
152 | |
---|
153 | do i=1,numbwf |
---|
154 | if ( ( useAvailable.eq.0 ).or.(numbwf.eq.1) ) then |
---|
155 | print *,' ' |
---|
156 | print *,wfname(i) |
---|
157 | call convertfields( i, metdata_format, dumpPath) |
---|
158 | else |
---|
159 | if (((ldirect*wftime(i).le.0).and. & |
---|
160 | (ldirect*wftime(i+1).gt.0)).or. & |
---|
161 | (ldirect*wftime(i).gt.0)) then |
---|
162 | print *,' ' |
---|
163 | print *,wfname(i) |
---|
164 | call convertfields( i, metdata_format, dumpPath) |
---|
165 | endif |
---|
166 | endif |
---|
167 | end do |
---|
168 | |
---|
169 | write(*,*) 'CONGRATULATIONS: YOU HAVE SUCCESSFULLY COMPLETED A GRIB2FLE& |
---|
170 | &XPART PREPROCESSING RUN!' |
---|
171 | |
---|
172 | end program grib2flexpart |
---|