source: trunk/MESOSCALE/LMD_MM_MARS/SRC/WPS/util/src/mod_levs.F90

Last change on this file was 11, checked in by aslmd, 14 years ago

spiga@svn-planeto:ajoute le modele meso-echelle martien

File size: 5.1 KB
Line 
1!  Program to modify levels in the intermediate format.  Two input
2!  files come in on the command line: input file and output file.
3!  An additional namelist file is used to select which pressure levels
4!  are to be kept.
5
6!  NRCM helper, WPS toy code
7
8PROGRAM mod_levs_prog
9
10   USE module_debug
11   USE read_met_module
12   USE write_met_module
13   USE misc_definitions_module
14
15   IMPLICIT NONE
16
17   !  Intermediate input and output from same source.
18
19   CHARACTER ( LEN =132 )            :: flnm, flnm2
20
21   INTEGER :: istatus, iop, version, nx, ny, iproj
22   integer :: idum, ilev
23   REAL :: xfcst, xlvl, startlat, startlon, starti, startj, &
24           deltalat, deltalon, dx, dy, xlonc, truelat1, truelat2, earth_radius
25   REAL, POINTER, DIMENSION(:,:) :: slab
26   LOGICAL :: is_wind_grid_rel
27
28   CHARACTER ( LEN = 24 )            :: hdate
29   CHARACTER ( LEN =  9 )            :: field
30   CHARACTER ( LEN = 25 )            :: units
31   CHARACTER ( LEN = 46 )            :: desc
32   CHARACTER ( LEN = 32 )            :: map_source
33
34   !  The namelist has a pressure array that we want.
35
36   LOGICAL                           :: keep_this_one
37   INTEGER                           :: l , max_pres_keep
38   INTEGER , PARAMETER               :: num_pres_lev = 1000
39   REAL, DIMENSION(num_pres_lev)     :: press_pa = -1.
40   NAMELIST /mod_levs/ press_pa
41
42   INTEGER , EXTERNAL :: lenner
43
44   !  Open up the file with the pressure levels to process.
45
46   OPEN ( UNIT   =  10            , &
47          FILE   = 'namelist.wps' , &
48          STATUS = 'OLD'          , &
49          FORM   = 'FORMATTED'    , &
50          IOSTAT =  iop              )
51
52   IF (iop .NE. 0) then
53      print *, 'Problem with namelist.input file, I can''t open it'
54      STOP
55   END IF
56
57   !  Input the pressure levels requested.
58
59   READ ( 10 , mod_levs )
60
61   CLOSE ( 10 )
62
63   !  How many pressure levels were asked for?
64
65   DO l = 1 , num_pres_lev
66      IF ( press_pa(l) .EQ. -1. ) THEN
67         max_pres_keep = l-1
68         EXIT
69      END IF
70   END DO
71
72   !  Get the two files: input and output.
73
74   CALL getarg ( 1 , flnm  )
75
76   IF ( flnm(1:1) .EQ. ' ' ) THEN
77      print *,'USAGE: mod_levs.exe FILE:2006-07-31_00 new_FILE:2006-07-31_00'
78      STOP
79   END IF
80
81   CALL getarg ( 2 , flnm2 )
82
83   l = lenner(flnm)
84   IF ( flnm2(1:1) .EQ. ' ' ) THEN
85      flnm2(5:l+4) = flnm(1:l)
86      flnm2(1:4) = 'new_'
87   END IF
88
89   CALL set_debug_level(WARN)
90
91   CALL read_met_init(TRIM(flnm), .true., '0000-00-00_00', istatus)
92
93   IF ( istatus == 0 ) THEN
94
95      CALL write_met_init(TRIM(flnm2), .true., '0000-00-00_00', istatus)
96
97      IF ( istatus == 0 ) THEN
98
99         CALL read_next_met_field(version, field, hdate, xfcst, xlvl, units, desc, &
100                           iproj, startlat, startlon, starti, startj, deltalat, &
101                           deltalon, dx, dy, xlonc, truelat1, truelat2, earth_radius, &
102                           nx, ny, map_source, &
103                           slab, is_wind_grid_rel, istatus)
104
105         DO WHILE (istatus == 0)
106   
107   
108            keep_this_one = .FALSE.
109            DO l = 1 , max_pres_keep
110               IF ( xlvl .EQ. press_pa(l) ) THEN
111                  keep_this_one = .TRUE.
112                  EXIT
113               END IF
114            END DO
115
116            IF (keep_this_one) THEN
117               CALL write_next_met_field(version, field, hdate, xfcst, xlvl, units, desc, &
118                                      iproj, startlat, startlon, starti, startj, deltalat, &
119                                      deltalon, dx, dy, xlonc, truelat1, truelat2, earth_radius, &
120                                      nx, ny, map_source, &
121                                      slab, is_wind_grid_rel, istatus)
122            ELSE
123               CALL mprintf(.true.,STDOUT,'Deleting level %f Pa',f1=xlvl)
124            END IF
125
126            CALL mprintf(.true.,STDOUT,'Processed %s at level %f for time %s', &
127                         s1=field, f1=xlvl, s2=hdate)
128            IF (ASSOCIATED(slab)) DEALLOCATE(slab)
129   
130            CALL read_next_met_field(version, field, hdate, xfcst, xlvl, units, desc, &
131                                iproj, startlat, startlon, starti, startj, deltalat, &
132                                deltalon, dx, dy, xlonc, truelat1, truelat2, earth_radius, &
133                                nx, ny, map_source, &
134                                slab, is_wind_grid_rel, istatus)
135         END DO
136
137         CALL write_met_close()
138
139      ELSE
140
141         print *, 'File = ',TRIM(flnm2)
142         print *, 'Problem with output file, I can''t open it'
143         STOP
144
145      END IF
146
147      CALL read_met_close()
148 
149   ELSE
150
151      print *, 'File = ',TRIM(flnm)
152      print *, 'Problem with input file, I can''t open it'
153      STOP
154
155   END IF
156
157   print *,'SUCCESSFUL COMPLETION OF PROGRAM MOD_LEVS'
158   STOP
159
160END PROGRAM mod_levs_prog
161   
162INTEGER FUNCTION lenner ( string )
163   CHARACTER ( LEN = 132 ) ::  string
164   INTEGER :: l
165   DO l = 132 , 1 , -1
166      IF ( ( ( string(l:l) .GE. 'A' ) .AND. ( string(l:l) .LE. 'Z' ) ) .OR. &
167           ( ( string(l:l) .GE. 'a' ) .AND. ( string(l:l) .LE. 'z' ) ) .OR. &
168           ( ( string(l:l) .GE. '0' ) .AND. ( string(l:l) .LE. '9' ) ) ) THEN
169         lenner = l
170         EXIT
171      END IF
172   END DO
173END FUNCTION lenner
Note: See TracBrowser for help on using the repository browser.