wrf svn trunk commit r4103
[wrffire.git] / wrfv2_fire / var / da / da_obs_io / da_write_iv_for_multi_inc.inc
blob8ce4f21feb5bc593eb76c4e44f68b2a3eed8ebc6
1 subroutine da_write_iv_for_multi_inc(file_index, iv)
3    !-------------------------------------------------------------------------
4    ! Purpose: Writes out components of iv=O-B structure.
5    !-------------------------------------------------------------------------   
7    implicit none
9    type (iv_type), intent(in)    :: iv      ! O-B structure.
10    integer, intent (in)          :: file_index
11       
12    integer                       :: n, k, ios
13    integer                       :: ounit     ! Output unit           
14    character(len=filename_len)   :: filename
16    if (trace_use) call da_trace_entry("da_write_iv_for_multi_inc")
18    !-------------------------------------------------------------------------
19    ! Fix output unit
20    !-------------------------------------------------------------------------
22    call da_get_unit(ounit)
24    write(unit=filename, fmt='(a,i3.3)') 'gts_omb.', file_index
26    ! [1] surface obs:
28    if (iv%info(synop)%plocal(iv%time) - iv%info(synop)%plocal(iv%time-1) > 0) then
30       open (unit=ounit,file=trim(filename)//'.synop',form='formatted',status='replace', &
31          iostat=ios)
32       if (ios /= 0) then
33          call da_error(__FILE__,__LINE__, &
34             (/"Cannot open conventional observation omb file"//filename/))
35       end if
37       write(ounit,'(a20,i8)')'synop',iv%info(synop)%plocal(iv%time) - &
38                                      iv%info(synop)%plocal(iv%time-1) 
39       do n = iv%info(synop)%plocal(iv%time-1) + 1, &
40              iv%info(synop)%plocal(iv%time)
41          write(ounit,'(i8,a5,2E22.13)')&
42              n , iv%info(synop)%id(n), &  ! Station
43              iv%info(synop)%lat(1,n), &       ! Latitude
44              iv%info(synop)%lon(1,n)          ! Longitude
45          write(ounit,'(E22.13,5(E22.13,i8,3E22.13))')&
46              iv%synop(n)%h, &
47              iv%synop(n)%u, &!  O-B u
48              iv%synop(n)%v, &!  O-B v
49              iv%synop(n)%t, &!  O-B t
50              iv%synop(n)%p, &!  O-B p
51              iv%synop(n)%q  !  O-B q
52       end do
53       close (ounit)
54    end if
56    ! [2] metar obs:
58    if (iv%info(metar)%plocal(iv%time) - iv%info(metar)%plocal(iv%time-1) > 0) then
60       open (unit=ounit,file=trim(filename)//'.metar',form='formatted',status='replace', &
61          iostat=ios)
62       if (ios /= 0) then
63          call da_error(__FILE__,__LINE__, &
64             (/"Cannot open conventional observation omb file"//filename/))
65       end if
67       write(ounit,'(a20,i8)')'metar', iv%info(metar)%plocal(iv%time) - &
68                                        iv%info(metar)%plocal(iv%time-1)
69       do n = iv%info(metar)%plocal(iv%time-1) + 1, &
70              iv%info(metar)%plocal(iv%time)
71          write(ounit,'(i8,a5,2E22.13)')&
72                  n, iv%info(metar)%id(n), &  ! Station
73                  iv%info(metar)%lat(1,n), &       ! Latitude
74                  iv%info(metar)%lon(1,n)          ! Longitude
75          write(ounit,'(E22.13,5(E22.13,i8,3E22.13))')&
76                  iv%metar(n)%h, & 
77                  iv%metar(n)%u, &! O-B u
78                  iv%metar(n)%v, &! O-B v
79                  iv%metar(n)%t, &! O-B t
80                  iv%metar(n)%p, &! O-B p
81                  iv%metar(n)%q   ! O-B q
82       end do
83       close (ounit)
84    end if
86    ! [3] ships obs:
88    if (iv%info(ships)%plocal(iv%time) - iv%info(ships)%plocal(iv%time-1) > 0) then
90       open (unit=ounit,file=trim(filename)//'.ships',form='formatted',status='replace', &
91          iostat=ios)
92       if (ios /= 0) then
93          call da_error(__FILE__,__LINE__, &
94             (/"Cannot open conventional observation omb file"//filename/))
95       end if
97       write(ounit,'(a20,i8)')'ships', iv%info(ships)%plocal(iv%time) - &
98                                        iv%info(ships)%plocal(iv%time-1)
99       do n = iv%info(ships)%plocal(iv%time-1) + 1, &
100              iv%info(ships)%plocal(iv%time)
101          write(ounit,'(i8,a5,2E22.13)')&
102                  n, iv%info(ships)%id(n), &  ! Station
103                  iv%info(ships)%lat(1,n), &       ! Latitude
104                  iv%info(ships)%lon(1,n)          ! Longitude
105          write(ounit,'(E22.13,5(E22.13,i8,3E22.13))')&
106                  iv%ships(n)%h, &
107                  iv%ships(n)%u, &! O-B u
108                  iv%ships(n)%v, &! O-B v
109                  iv%ships(n)%t, &! O-B t
110                  iv%ships(n)%p, &! O-B p
111                  iv%ships(n)%q   ! O-B q
112       end do
113       close (ounit)
114    end if
116    ! [4] sonde_sfc obs:
118    if (iv%info(sound)%plocal(iv%time) - iv%info(sound)%plocal(iv%time-1) > 0) then
120       open (unit=ounit,file=trim(filename)//'.sonde_sfc',form='formatted',status='replace', &
121          iostat=ios)
122       if (ios /= 0) then
123          call da_error(__FILE__,__LINE__, &
124             (/"Cannot open conventional observation omb file"//filename/))
125       end if
127       write(ounit,'(a20,i8)')'sonde_sfc', iv%info(sound)%plocal(iv%time) - &
128                                        iv%info(sound)%plocal(iv%time-1)
129       do n = iv%info(sound)%plocal(iv%time-1) + 1, &
130              iv%info(sound)%plocal(iv%time)
131          write(ounit,'(i8,a5,2E22.13)')&
132                  n, iv%info(sonde_sfc)%id(n), &  ! Station
133                  iv%info(sonde_sfc)%lat(1,n), &       ! Latitude
134                  iv%info(sonde_sfc)%lon(1,n)          ! Longitude
135          write(ounit,'(E22.13,5(E22.13,i8,3E22.13))')&
136                  iv%sonde_sfc(n) % h, &
137                  iv%sonde_sfc(n)%u, &! O-B u
138                  iv%sonde_sfc(n)%v, &! O-B v
139                  iv%sonde_sfc(n)%t, &! O-B t
140                  iv%sonde_sfc(n)%p, &! O-B p
141                  iv%sonde_sfc(n)%q   ! O-B q
142       end do
143       close (ounit)
144    end if
146    ! [5] sound obs:
148    if (iv%info(sound)%plocal(iv%time) - iv%info(sound)%plocal(iv%time-1) > 0) then
150       open (unit=ounit,file=trim(filename)//'.sound',form='formatted',status='replace', &
151          iostat=ios)
152       if (ios /= 0) then
153          call da_error(__FILE__,__LINE__, &
154             (/"Cannot open conventional observation omb file"//filename/))
155       end if
157       write(ounit,'(a20,i8)')'sound', iv%info(sound)%plocal(iv%time) - &
158                                        iv%info(sound)%plocal(iv%time-1)
159       do n = iv%info(sound)%plocal(iv%time-1) + 1, &
160              iv%info(sound)%plocal(iv%time)
161          write(ounit,'(2i8,a5,2E22.13)')&
162                  n, iv%info(sound)%levels(n), iv%info(sound)%id(n), &  ! Station
163                  iv%info(sound)%lat(1,n), &       ! Latitude
164                  iv%info(sound)%lon(1,n)          ! Longitude
165          do k = 1 , iv%info(sound)%levels(n)
166             write(ounit,'(2E22.13,4(E22.13,i8,3E22.13))')&
167                      iv%sound(n)%h(k), &
168                      iv%sound(n)%p(k), &             ! Obs Pressure
169                      iv%sound(n)%u(k), &! O-B u
170                      iv%sound(n)%v(k), &! O-B v
171                      iv%sound(n)%t(k), &! O-B t
172                      iv%sound(n)%q(k)   ! O-B q
173          enddo
174       end do
175       close (ounit)
176    end if
178    ! [6] buoy obs:
180    if (iv%info(buoy)%plocal(iv%time) - iv%info(buoy)%plocal(iv%time-1) > 0) then
182       open (unit=ounit,file=trim(filename)//'.buoy',form='formatted',status='replace', &
183          iostat=ios)
184       if (ios /= 0) then
185          call da_error(__FILE__,__LINE__, &
186             (/"Cannot open conventional observation omb file"//filename/))
187       end if
189       write(ounit,'(a20,i8)')'buoy', iv%info(buoy)%plocal(iv%time) - &
190                                        iv%info(buoy)%plocal(iv%time-1)
191       do n = iv%info(buoy)%plocal(iv%time-1) + 1, &
192              iv%info(buoy)%plocal(iv%time)
193          write(ounit,'(i8,a5,2E22.13)')&
194                  n, iv%info(buoy)%id(n), &  ! Station
195                  iv%info(buoy)%lat(1,n), &       ! Latitude
196                  iv%info(buoy)%lon(1,n)          ! Longitude
197          write(ounit,'(E22.13,5(E22.13,i8,3E22.13))')&
198                  iv%buoy(n)%h, &
199                  iv%buoy(n)%u, &! O-B u
200                  iv%buoy(n)%v, &! O-B v
201                  iv%buoy(n)%t, &! O-B t
202                  iv%buoy(n)%p, &! O-B p
203                  iv%buoy(n)%q   ! O-B q
204       end do
205       close (ounit)
206    end if
208    ! [7] Geo AMVs obs:
210    if (iv%info(geoamv)%plocal(iv%time) - iv%info(geoamv)%plocal(iv%time-1) > 0) then
212       open (unit=ounit,file=trim(filename)//'.geoamv',form='formatted',status='replace', &
213          iostat=ios)
214       if (ios /= 0) then
215          call da_error(__FILE__,__LINE__, &
216             (/"Cannot open conventional observation omb file"//filename/))
217       end if
219       write(ounit,'(a20,i8)')'geoamv', iv%info(geoamv)%plocal(iv%time) - &
220                                        iv%info(geoamv)%plocal(iv%time-1)
221       do n = iv%info(geoamv)%plocal(iv%time-1) + 1, &
222              iv%info(geoamv)%plocal(iv%time)
223          write(ounit,'(2i8,a5,2E22.13)')&
224                  n, iv%info(geoamv)%levels(n), iv%info(geoamv)%id(n), &     ! Station
225                  iv%info(geoamv)%lat(1,n), &       ! Latitude
226                  iv%info(geoamv)%lon(1,n)          ! Longitude
227          do k = 1 , iv%info(geoamv)%levels(n)
228             write(ounit,'(E22.13,2(E22.13,i8,3E22.13))')&
229                       iv%geoamv(n)%p(k), &                ! Obs Pressure
230                       iv%geoamv(n)%u(k), &! O-B u
231                       iv%geoamv(n)%v(k)
232          enddo
233       end do
234       close (ounit)
235    end if
237    ! [8] gpspw obs:
239    if (iv%info(gpspw)%plocal(iv%time) - iv%info(gpspw)%plocal(iv%time-1) > 0) then
241       open (unit=ounit,file=trim(filename)//'.gpspw',form='formatted',status='replace', &
242          iostat=ios)
243       if (ios /= 0) then
244          call da_error(__FILE__,__LINE__, &
245             (/"Cannot open conventional observation omb file"//filename/))
246       end if
248       write(ounit,'(a20,i8)')'gpspw', iv%info(gpspw)%plocal(iv%time) - &
249                                        iv%info(gpspw)%plocal(iv%time-1)
250       do n = iv%info(gpspw)%plocal(iv%time-1) + 1, &
251              iv%info(gpspw)%plocal(iv%time)
252          write(ounit,'(i8,a5,2E22.13)')&
253                  n, iv%info(gpspw)%id(n), &  ! Station
254                  iv%info(gpspw)%lat(1,n), &       ! Latitude
255                  iv%info(gpspw)%lon(1,n)          ! Longitude
256          write(ounit,'(E22.13,i8,3E22.13)')&
257               iv%gpspw(n)%tpw
258       end do
259       close (ounit)
260    end if
262    ! [9] SSM/I obs:
264    if (iv%info(ssmi_rv)%plocal(iv%time) - iv%info(ssmi_rv)%plocal(iv%time-1) > 0) then
266       open (unit=ounit,file=trim(filename)//'.ssmir',form='formatted',status='replace', &
267          iostat=ios)
268       if (ios /= 0) then
269          call da_error(__FILE__,__LINE__, &
270             (/"Cannot open conventional observation omb file"//filename/))
271       end if
273       write(ounit,'(a20,i8)')'ssmir', iv%info(ssmi_rv)%plocal(iv%time) - &
274                                        iv%info(ssmi_rv)%plocal(iv%time-1)
275       do n = iv%info(ssmi_rv)%plocal(iv%time-1) + 1, &
276              iv%info(ssmi_rv)%plocal(iv%time)
277          write(ounit,'(i8,2E22.13)')&
278                  n, &  ! Station
279                  iv%info(ssmi_rv)%lat(1,n), &       ! Latitude
280                  iv%info(ssmi_rv)%lon(1,n)          ! Longitude
281          write(ounit,'(2(E22.13,i8,3E22.13))')&
282                  iv%ssmi_rv(n)%speed, & ! O-B speed
283                  iv%ssmi_rv(n)%tpw ! O-BA tpw
284       end do
285       close (ounit)
286    end if
288    ! [10] airep obs:
290    if (iv%info(airep)%plocal(iv%time) - iv%info(airep)%plocal(iv%time-1) > 0) then
292       open (unit=ounit,file=trim(filename)//'.airep',form='formatted',status='replace', &
293          iostat=ios)
294       if (ios /= 0) then
295          call da_error(__FILE__,__LINE__, &
296             (/"Cannot open conventional observation omb file"//filename/))
297       end if
299       write(ounit,'(a20,i8)')'airep', iv%info(airep)%plocal(iv%time) - &
300                                        iv%info(airep)%plocal(iv%time-1)
301       do n = iv%info(airep)%plocal(iv%time-1) + 1, &
302              iv%info(airep)%plocal(iv%time)
303          write(ounit,'(2i8,a5,2E22.13)')&
304                  n, iv%info(airep)%levels(n), iv%info(airep)%id(n), &  ! Station
305                  iv%info(airep)%lat(1,n), &       ! Latitude
306                  iv%info(airep)%lon(1,n)          ! Longitude
307          do k = 1 , iv%info(airep)%levels(n)
308             write(ounit,'(2E22.13,3(E22.13,i8,3E22.13))')&
309                      iv%airep(n)%h(k), &
310                      iv%airep(n)%p(k), &             ! Obs pressure
311                      iv%airep(n)%u(k), &! O-B u
312                      iv%airep(n)%v(k), &! O-B v
313                      iv%airep(n)%t(k)
314          enddo
315       end do
316       close (ounit)
317    end if
319    ! [11] Polar AMVs obs:
321    if (iv%info(polaramv)%plocal(iv%time) - iv%info(polaramv)%plocal(iv%time-1) > 0) then
323       open (unit=ounit,file=trim(filename)//'.polaramv',form='formatted',status='replace', &
324          iostat=ios)
325       if (ios /= 0) then
326          call da_error(__FILE__,__LINE__, &
327             (/"Cannot open conventional observation omb file"//filename/))
328       end if
330       write(ounit,'(a20,i8)')'polaramv', iv%info(polaramv)%plocal(iv%time) - &
331                                        iv%info(polaramv)%plocal(iv%time-1)
332       do n = iv%info(polaramv)%plocal(iv%time-1) + 1, &
333              iv%info(polaramv)%plocal(iv%time)
334          write(ounit,'(2i8,a5,2E22.13)')&
335                  n, iv%info(polaramv)%levels(n), iv%info(polaramv)%id(n), &  ! Station
336                  iv%info(polaramv)%lat(1,n), &       ! Latitude
337                  iv%info(polaramv)%lon(1,n)          ! Longitude
338          do k = 1 , iv%info(polaramv)%levels(n)
339             write(ounit,'(E22.13,2(E22.13,i8,3E22.13))')&
340                       iv%polaramv(n)%p(k), &                ! Obs Pressure
341                       iv%polaramv(n)%u(k), &! O-B u
342                       iv%polaramv(n)%v(k)
343          enddo
344       end do
345       close (ounit)
346    end if
348    ! [12] pilot obs:
350    if (iv%info(pilot)%plocal(iv%time) - iv%info(pilot)%plocal(iv%time-1) > 0) then
352       open (unit=ounit,file=trim(filename)//'.pilot',form='formatted',status='replace', &
353          iostat=ios)
354       if (ios /= 0) then
355          call da_error(__FILE__,__LINE__, &
356             (/"Cannot open conventional observation omb file"//filename/))
357       end if
359       write(ounit,'(a20,i8)')'pilot', iv%info(pilot)%plocal(iv%time) - &
360                                        iv%info(pilot)%plocal(iv%time-1)
361       do n = iv%info(pilot)%plocal(iv%time-1) + 1, &
362              iv%info(pilot)%plocal(iv%time)
363          write(ounit,'(2i8,a5,2E22.13)')&
364                  n, iv%info(pilot)%levels(n), iv%info(pilot)%id(n), &  ! Station
365                  iv%info(pilot)%lat(1,n), &       ! Latitude
366                  iv%info(pilot)%lon(1,n)          ! Longitude
367          do k = 1 , iv%info(pilot)%levels(n)
368             write(ounit,'(E22.13,2(E22.13,i8,3E22.13))')&
369                       iv%pilot(n)%p(k), &                ! Obs Pressure
370                       iv%pilot(n)%u(k), &! O-B u
371                       iv%pilot(n)%v(k)
372          enddo
373       end do
374       close (ounit)
375    end if
377    ! [13] ssmi_tb obs:
379    if (iv%info(ssmi_tb)%plocal(iv%time) - iv%info(ssmi_tb)%plocal(iv%time-1) > 0) then
381       open (unit=ounit,file=trim(filename)//'.ssmi_tb',form='formatted',status='replace', &
382          iostat=ios)
383       if (ios /= 0) then
384          call da_error(__FILE__,__LINE__, &
385             (/"Cannot open conventional observation omb file"//filename/))
386       end if
388       write(ounit,'(a20,i8)')'ssmi_tb', iv%info(ssmi_tb)%plocal(iv%time) - &
389                                        iv%info(ssmi_tb)%plocal(iv%time-1)
390       do n = iv%info(ssmi_tb)%plocal(iv%time-1) + 1, &
391              iv%info(ssmi_tb)%plocal(iv%time)
392          write(ounit,'(i8,2E22.13)')&
393                  n, &  ! Station
394                  iv%info(ssmi_tb)%lat(1,n), &       ! Latitude
395                  iv%info(ssmi_tb)%lon(1,n)          ! Longitude
396          write(ounit,'(7(E22.13,i8,3E22.13))')&
397                  iv%ssmi_tb(n)%tb19h, & ! O-B Tb19h
398                  iv%ssmi_tb(n)%tb19v, & ! O-B Tb19v
399                  iv%ssmi_tb(n)%tb22v, & ! O-B Tb22v
400                  iv%ssmi_tb(n)%tb37h, & ! O-B Tb37h
401                  iv%ssmi_tb(n)%tb37v, & ! O-B Tb37v
402                  iv%ssmi_tb(n)%tb85h, & ! O-B Tb85h
403                  iv%ssmi_tb(n)%tb85v    ! O-B Tb85v
404       end do
405       close (ounit)
406    end if
408    ! [14] satem obs:
410    if (iv%info(satem)%plocal(iv%time) - iv%info(satem)%plocal(iv%time-1) > 0) then
412       open (unit=ounit,file=trim(filename)//'.satem',form='formatted',status='replace', &
413          iostat=ios)
414       if (ios /= 0) then
415          call da_error(__FILE__,__LINE__, &
416             (/"Cannot open conventional observation omb file"//filename/))
417       end if
419       write(ounit,'(a20,i8)')'satem', iv%info(satem)%plocal(iv%time) - &
420                                        iv%info(satem)%plocal(iv%time-1)
421       do n = iv%info(satem)%plocal(iv%time-1) + 1, &
422              iv%info(satem)%plocal(iv%time)
423          write(ounit,'(2i8,a5,2E22.13)')&
424                  n, iv%info(satem)%levels(n), iv%info(satem)%id(n), &  ! Station
425                  iv%info(satem)%lat(1,n), &       ! Latitude
426                  iv%info(satem)%lon(1,n)          ! Longitude
427          do k = 1 , iv%info(satem)%levels(n)
428             write(ounit,'(E22.13,(E22.13,i8,3E22.13))')&
429                  iv%satem(n)%p(k), &             ! Obs Pressure
430                  iv%satem(n)%thickness(k)
431          enddo
432       end do
433       close (ounit)
434    end if
436    ! [15] ssmt1 obs:
438    if (iv%info(ssmt1)%plocal(iv%time) - iv%info(ssmt1)%plocal(iv%time-1) > 0) then
440       open (unit=ounit,file=trim(filename)//'.ssmt1',form='formatted',status='replace', &
441          iostat=ios)
442       if (ios /= 0) then
443          call da_error(__FILE__,__LINE__, &
444             (/"Cannot open conventional observation omb file"//filename/))
445       end if
447       write(ounit,'(a20,i8)')'ssmt1', iv%info(ssmt1)%plocal(iv%time) - &
448                                        iv%info(ssmt1)%plocal(iv%time-1)
449       do n = iv%info(ssmt1)%plocal(iv%time-1) + 1, &
450              iv%info(ssmt1)%plocal(iv%time)
451          write(ounit,'(2i8,a5,2E22.13)')&
452                  n, iv%info(ssmt1)%levels(n), iv%info(ssmt1)%id(n), &  ! Station
453                  iv%info(ssmt1)%lat(1,n), &       ! Latitude
454                  iv%info(ssmt1)%lon(1,n)          ! Longitude
455          do k = 1 , iv%info(ssmt1)%levels(n)
456             write(ounit,'(E22.13,(E22.13,i8,3E22.13))')&
457                   iv%ssmt1(n)%h(k), &             ! Obs height
458                   iv%ssmt1(n)%t(k)
459          enddo
460       end do
461       close (ounit)
462    end if
464    ! [16] ssmt2 obs:
466    if (iv%info(ssmt2)%plocal(iv%time) - iv%info(ssmt2)%plocal(iv%time-1) > 0) then
468       open (unit=ounit,file=trim(filename)//'.ssmt2',form='formatted',status='replace', &
469          iostat=ios)
470       if (ios /= 0) then
471          call da_error(__FILE__,__LINE__, &
472             (/"Cannot open conventional observation omb file"//filename/))
473       end if
475       write(ounit,'(a20,i8)')'ssmt2', iv%info(ssmt2)%plocal(iv%time) - &
476                                        iv%info(ssmt2)%plocal(iv%time-1)
477       do n = iv%info(ssmt2)%plocal(iv%time-1) + 1, &
478              iv%info(ssmt2)%plocal(iv%time)
479          write(ounit,'(2i8,a5,2E22.13)')&
480                  n, iv%info(ssmt2)%levels(n), iv%info(ssmt2)%id(n), &  ! Station
481                  iv%info(ssmt2)%lat(1,n), &       ! Latitude
482                  iv%info(ssmt2)%lon(1,n)           ! Longitude
483          do k = 1 , iv%info(ssmt2)%levels(n)
484             write(ounit,'(E22.13,(E22.13,i8,3E22.13))')&
485                   iv%ssmt2(n)%h(k), &             ! Obs height
486                   iv%ssmt2(n)%rh(k)
487          enddo
488       end do
489       close (ounit)
490    end if
492    ! [17] scatterometer obs:
494    if (iv%info(qscat)%plocal(iv%time) - iv%info(qscat)%plocal(iv%time-1) > 0) then
496       open (unit=ounit,file=trim(filename)//'.qscat',form='formatted',status='replace', &
497          iostat=ios)
498       if (ios /= 0) then
499          call da_error(__FILE__,__LINE__, &
500             (/"Cannot open conventional observation omb file"//filename/))
501       end if
503       write(ounit,'(a20,i8)')'qscat', iv%info(qscat)%plocal(iv%time) - &
504                                        iv%info(qscat)%plocal(iv%time-1)
505       do n = iv%info(qscat)%plocal(iv%time-1) + 1, &
506              iv%info(qscat)%plocal(iv%time)
507          write(ounit,'(i8,a5,2E22.13)')&
508                  n, iv%info(qscat)%id(n), &  ! Station
509                  iv%info(qscat)%lat(1,n), &       ! Latitude
510                  iv%info(qscat)%lon(1,n)          ! Longitude
511          write(ounit,'(E22.13,2(E22.13,i8,3E22.13))')&
512                    iv%qscat(n)%h, &                ! Obs height
513                    iv%qscat(n)%u, &! O-B u
514                    iv%qscat(n)%v   ! O-B v
515       end do
516       close (ounit)
517    end if
519    ! [18] profiler obs:
521    if (iv%info(profiler)%plocal(iv%time) - iv%info(profiler)%plocal(iv%time-1) > 0) then
523       open (unit=ounit,file=trim(filename)//'.profiler',form='formatted',status='replace', &
524          iostat=ios)
525       if (ios /= 0) then
526          call da_error(__FILE__,__LINE__, &
527             (/"Cannot open conventional observation omb file"//filename/))
528       end if
530       write(ounit,'(a20,i8)')'profiler', iv%info(profiler)%plocal(iv%time) - &
531                                        iv%info(profiler)%plocal(iv%time-1)
532       do n = iv%info(profiler)%plocal(iv%time-1) + 1, &
533              iv%info(profiler)%plocal(iv%time)
534          write(ounit,'(2i8,a5,2E22.13)')&
535                  n, iv%info(profiler)%levels(n), iv%info(profiler)%id(n), &  ! Station
536                  iv%info(profiler)%lat(1,n), &       ! Latitude
537                  iv%info(profiler)%lon(1,n)          ! Longitude
538          do k = 1 , iv%info(profiler)%levels(n)
539             write(ounit,'(E22.13,2(E22.13,i8,3E22.13))')&
540                      iv%profiler(n)%p(k), &             ! Obs Pressure
541                      iv%profiler(n)%u(k), &! O-B u
542                      iv%profiler(n)%v(k) ! O-B v
543          enddo
544       end do
545       close (ounit)
546    end if
548    ! [19] TC bogus obs:
550    if (iv%info(bogus)%plocal(iv%time) - iv%info(bogus)%plocal(iv%time-1) > 0) then
552       open (unit=ounit,file=trim(filename)//'.bogus',form='formatted',status='replace', &
553          iostat=ios)
554       if (ios /= 0) then
555          call da_error(__FILE__,__LINE__, &
556             (/"Cannot open conventional observation omb file"//filename/))
557       end if
559       write(ounit,'(a20,i8)')'bogus', iv%info(bogus)%plocal(iv%time) - &
560                                        iv%info(bogus)%plocal(iv%time-1)
561       do n = iv%info(bogus)%plocal(iv%time-1) + 1, &
562              iv%info(bogus)%plocal(iv%time)
563          write(ounit,'(2i8,a5,2E22.13)')&
564                  n, iv%info(bogus)%levels(n), iv%info(bogus)%id(n), &  ! Station
565                  iv%info(bogus)%lat(1,n), &     ! Latitude
566                  iv%info(bogus)%lon(1,n)        ! Longitude
567          write(ounit,'(E22.13,i8,3E22.13)')&
568                  iv%bogus(n)%slp    ! O-B p
569          do k = 1 , iv%info(bogus)%levels(n)
570             write(ounit,'(2E22.13,4(E22.13,i8,3E22.13))')&
571                      iv%bogus(n)%h(k), &
572                      iv%bogus(n)%p(k), &             ! Obs Pressure
573                      iv%bogus(n)%u(k), &! O-B u
574                      iv%bogus(n)%v(k), &! O-B v
575                      iv%bogus(n)%t(k), &! O-B t
576                      iv%bogus(n)%q(k)   ! O-B q
577          enddo
578       end do
579       close (ounit)
580    end if
582    ! [20] AIRS retrievals:
584    if (iv%info(airsr)%plocal(iv%time) - iv%info(airsr)%plocal(iv%time-1) > 0) then
586       open (unit=ounit,file=trim(filename)//'.airsr',form='formatted',status='replace', &
587          iostat=ios)
588       if (ios /= 0) then
589          call da_error(__FILE__,__LINE__, &
590             (/"Cannot open conventional observation omb file"//filename/))
591       end if
593       write(ounit,'(a20,i8)')'airsr', iv%info(airsr)%plocal(iv%time) - &
594                                        iv%info(airsr)%plocal(iv%time-1)
595       do n = iv%info(airsr)%plocal(iv%time-1) + 1, &
596              iv%info(airsr)%plocal(iv%time)
597          write(ounit,'(2i8,a5,2E22.13)')&
598                  n, iv%info(airsr)%levels(n), iv%info(airsr)%id(n), &  ! Station
599                  iv%info(airsr)%lat(1,n), &    ! Latitude
600                  iv%info(airsr)%lon(1,n)       ! Longitude
601          do k = 1 , iv%info(airsr)%levels(n)
602             write(ounit,'(E22.13,2(E22.13,i8,3E22.13))')&
603                      iv%airsr(n)%p(k), &             ! Obs Pressure
604                      iv%airsr(n)%t(k), &! O-B t
605                      iv%airsr(n)%q(k)   ! O-B q
606          enddo
607       end do
608       close (ounit)
609    end if
611    ! [21] gpsref obs:
613    if (iv%info(gpsref)%plocal(iv%time) - iv%info(gpsref)%plocal(iv%time-1) > 0) then
615       open (unit=ounit,file=trim(filename)//'.gpsref',form='formatted',status='replace', &
616          iostat=ios)
617       if (ios /= 0) then
618          call da_error(__FILE__,__LINE__, &
619             (/"Cannot open conventional observation omb file"//filename/))
620       end if
622       write(ounit,'(a20,i8)')'gpsref', iv%info(gpsref)%plocal(iv%time) - &
623                                        iv%info(gpsref)%plocal(iv%time-1)
624       do n = iv%info(gpsref)%plocal(iv%time-1) + 1, &
625              iv%info(gpsref)%plocal(iv%time)
626          write(ounit,'(2i8,a5,2E22.13)')&
627                  n, iv%info(gpsref)%levels(n), iv%info(gpsref)%id(n), &  ! Station
628                  iv%info(gpsref)%lat(1,n), &    ! Latitude
629                  iv%info(gpsref)%lon(1,n)       ! Longitude
630          do k = 1 , iv%info(gpsref)%levels(n)
631             write(ounit,'(E22.13,(E22.13,i8,3E22.13))')&
632                      iv%gpsref(n)%h(k), &             ! Obs Height
633                      iv%gpsref(n)%ref(k) ! O-B ref
634          enddo
635       end do
636       close (ounit)
637    end if
639    ! [22] radar obs:
641    if (iv%info(radar)%plocal(iv%time) - iv%info(radar)%plocal(iv%time-1) > 0) then
643       open (unit=ounit,file=trim(filename)//'.radar',form='formatted',status='replace', &
644          iostat=ios)
645       if (ios /= 0) then
646          call da_error(__FILE__,__LINE__, &
647             (/"Cannot open conventional observation omb file"//filename/))
648       end if
650       write(ounit,'(a20,i8)')'radar', iv%info(radar)%plocal(iv%time) - &
651                                        iv%info(radar)%plocal(iv%time-1)
652       do n = iv%info(radar)%plocal(iv%time-1) + 1, &
653              iv%info(radar)%plocal(iv%time)
654          write(ounit,'(2i8,2E22.13)')&
655                  n, iv%info(radar)%levels(n),  &
656                  iv%info(radar)%lat(1,n), &      ! Latitude
657                  iv%info(radar)%lon(1,n)         ! Longitude
658          do k = 1 , iv%info(radar)%levels(n)
659             write(ounit,'(E22.13,i8,3E22.13)')&
660                      iv%radar(n)%rv(k)           ! radar_rv
662          enddo
663       end do
664       close (ounit)
665    end if
669    !-------------------------------------------------------------------------------
672    call da_free_unit(ounit)
674    if (trace_use) call da_trace_exit("da_write_iv_for_multi_inc")
676 end subroutine da_write_iv_for_multi_inc