New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
obs_read_seaice.F90 in branches/UKMO/dev_rev5518_OBS_DoNotAssim/NEMOGCM/NEMO/OPA_SRC/OBS – NEMO

source: branches/UKMO/dev_rev5518_OBS_DoNotAssim/NEMOGCM/NEMO/OPA_SRC/OBS/obs_read_seaice.F90 @ 7841

Last change on this file since 7841 was 7841, checked in by jwhile, 7 years ago

Added "Do not Assimlate" funtionality to OBS code

  • Property svn:keywords set to Id
File size: 17.7 KB
Line 
1MODULE obs_read_seaice
2   !!======================================================================
3   !!                       ***  MODULE obs_read_seaice  ***
4   !! Observation diagnostics: Read the along track SEAICE data from
5   !!                          GHRSST or any SEAICE data from feedback files
6   !!======================================================================
7
8   !!----------------------------------------------------------------------
9   !!   obs_rea_seaice : Driver for reading seaice data from the GHRSST/feedback
10   !!----------------------------------------------------------------------
11
12   !! * Modules used   
13   USE par_kind                 ! Precision variables
14   USE in_out_manager           ! I/O manager
15   USE dom_oce                  ! Ocean space and time domain variables
16   USE obs_mpp                  ! MPP support routines for observation diagnostics
17   USE julian                   ! Julian date routines
18   USE obs_utils                ! Observation operator utility functions
19   USE obs_grid                 ! Grid search
20   USE obs_sort                 ! Sorting observation arrays
21   USE obs_surf_def             ! Surface observation definitions
22   USE obs_types                ! Observation type definitions
23   USE obs_seaice_io            ! I/O for seaice files
24   USE iom                      ! I/O of fields for Reynolds data
25   USE netcdf                   ! NetCDF library
26
27   IMPLICIT NONE
28
29   !! * Routine accessibility
30   PRIVATE
31
32   PUBLIC obs_rea_seaice      ! Read the seaice observations from the point data
33   
34   !!----------------------------------------------------------------------
35   !! NEMO/OPA 3.3 , NEMO Consortium (2010)
36   !! $Id$
37   !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
38   !!----------------------------------------------------------------------
39
40CONTAINS
41
42   SUBROUTINE obs_rea_seaice( kformat, &
43      &                    seaicedata, knumfiles, cfilenames, &
44      &                    kvars, kextr, kstp, ddobsini, ddobsend, &
45      &                    ldignmis, ldmod )
46      !!---------------------------------------------------------------------
47      !!
48      !!                   *** ROUTINE obs_rea_seaice ***
49      !!
50      !! ** Purpose : Read from file the seaice data
51      !!
52      !! ** Method  : Depending on kformat either AVISO or
53      !!              feedback data files are read
54      !!
55      !! ** Action  :
56      !!
57      !!
58      !! History : 
59      !!      ! :  2009-01 (K. Mogensen) Initial version based on old versions
60      !!----------------------------------------------------------------------
61      !! * Modules used
62
63      !! * Arguments
64      INTEGER :: kformat   ! Format of input data
65      !                    ! 0: Feedback
66      !                    ! 1: GHRSST
67      TYPE(obs_surf), INTENT(INOUT) :: &
68         & seaicedata     ! seaice data to be read
69      INTEGER, INTENT(IN) :: knumfiles   ! Number of corio format files to read in
70      CHARACTER(LEN=128), INTENT(IN) :: cfilenames(knumfiles) ! File names to read in
71      INTEGER, INTENT(IN) :: kvars    ! Number of variables in seaicedata
72      INTEGER, INTENT(IN) :: kextr    ! Number of extra fields for each var in seaicedata
73      INTEGER, INTENT(IN) :: kstp     ! Ocean time-step index
74      LOGICAL, INTENT(IN) :: ldignmis   ! Ignore missing files
75      LOGICAL, INTENT(IN) :: ldmod      ! Initialize model from input data
76      REAL(KIND=dp), INTENT(IN) :: ddobsini    ! Obs. ini time in YYYYMMDD.HHMMSS
77      REAL(KIND=dp), INTENT(IN) :: ddobsend    ! Obs. end time in YYYYMMDD.HHMMSS
78         
79      !! * Local declarations
80      CHARACTER(LEN=14), PARAMETER :: cpname='obs_rea_seaice'
81      INTEGER :: ji
82      INTEGER :: jj
83      INTEGER :: jk
84      INTEGER :: iflag
85      INTEGER :: inobf
86      INTEGER :: i_file_id
87      INTEGER :: inowin
88      INTEGER :: iyea
89      INTEGER :: imon
90      INTEGER :: iday
91      INTEGER :: ihou
92      INTEGER :: imin
93      INTEGER :: isec
94      INTEGER, DIMENSION(knumfiles) :: &
95         & irefdate
96      INTEGER :: iobsmpp
97      INTEGER, PARAMETER :: iseaicemaxtype = 1024
98      INTEGER, DIMENSION(0:iseaicemaxtype) :: &
99         & ityp, &
100         & itypmpp
101      INTEGER, DIMENSION(:), ALLOCATABLE :: &
102         & iobsi,    &
103         & iobsj,    &
104         & iproc,    &
105         & iindx,    &
106         & ifileidx, &
107         & iseaiceidx
108      INTEGER :: itype
109      REAL(wp), DIMENSION(:), ALLOCATABLE :: &
110         & zphi, &
111         & zlam
112      real(wp), DIMENSION(:), ALLOCATABLE :: &
113         & zdat
114      LOGICAL :: llvalprof
115      TYPE(obfbdata), POINTER, DIMENSION(:) :: &
116         & inpfiles
117      real(wp), DIMENSION(knumfiles) :: &
118         & djulini, &
119         & djulend
120      INTEGER :: iobs
121      INTEGER :: iobstot
122      INTEGER :: ios
123      INTEGER :: ioserrcount
124      CHARACTER(len=8) :: cl_refdate
125   
126      ! Local initialization
127      iobs = 0
128 
129      !-----------------------------------------------------------------------
130      ! Check data the model part is just with feedback data files
131      !-----------------------------------------------------------------------
132      IF ( ldmod .AND. ( kformat /= 0 ) ) THEN
133         CALL ctl_stop( 'Model can only be read from feedback data' )
134         RETURN
135      ENDIF
136
137      !-----------------------------------------------------------------------
138      ! Count the number of files needed and allocate the obfbdata type
139      !-----------------------------------------------------------------------
140     
141      inobf = knumfiles
142     
143      ALLOCATE( inpfiles(inobf) )
144
145      seaice_files : DO jj = 1, inobf
146         
147         !---------------------------------------------------------------------
148         ! Prints
149         !---------------------------------------------------------------------
150         IF(lwp) THEN
151            WRITE(numout,*)
152            WRITE(numout,*) ' obs_rea_seaice : Reading from file = ', &
153               & TRIM( TRIM( cfilenames(jj) ) )
154            WRITE(numout,*) ' ~~~~~~~~~~~~~~'
155            WRITE(numout,*)
156         ENDIF
157
158         !---------------------------------------------------------------------
159         !  Initialization: Open file and get dimensions only
160         !---------------------------------------------------------------------
161         
162         iflag = nf90_open( TRIM( TRIM( cfilenames(jj) ) ), nf90_nowrite, &
163            &                      i_file_id )
164         
165         IF ( iflag /= nf90_noerr ) THEN
166
167            IF ( ldignmis ) THEN
168               inpfiles(jj)%nobs = 0
169               CALL ctl_warn( 'File ' // TRIM( TRIM( cfilenames(jj) ) ) // &
170                  &           ' not found' )
171            ELSE
172               CALL ctl_stop( 'File ' // TRIM( TRIM( cfilenames(jj) ) ) // &
173                  &           ' not found' )
174            ENDIF
175
176         ELSE 
177           
178            !------------------------------------------------------------------
179            !  Close the file since it is opened in read_proffile
180            !------------------------------------------------------------------
181           
182            iflag = nf90_close( i_file_id )
183
184            !------------------------------------------------------------------
185            !  Read the profile file into inpfiles
186            !------------------------------------------------------------------
187            IF ( kformat == 0 ) THEN
188               CALL init_obfbdata( inpfiles(jj) )
189               IF(lwp) THEN
190                  WRITE(numout,*)
191                  WRITE(numout,*)'Reading from feedback file :', &
192                     &           TRIM( cfilenames(jj) )
193               ENDIF
194               CALL read_obfbdata( TRIM( cfilenames(jj) ), inpfiles(jj), &
195                  &                ldgrid = .TRUE. )
196               IF ( ldmod .AND. ( ( inpfiles(jj)%nadd == 0 ) .OR.&
197                  &               ( inpfiles(jj)%next < 2 ) ) ) THEN
198                  CALL ctl_stop( 'Model not in input data' )
199                  RETURN
200               ENDIF
201            ELSEIF ( kformat == 1) THEN
202               CALL read_seaice( TRIM( cfilenames(jj) ), inpfiles(jj), &
203               &                 numout, lwp, .TRUE. )
204            ELSE
205               CALL ctl_stop( 'File format unknown' )
206            ENDIF
207
208            !------------------------------------------------------------------
209            !  Change longitude (-180,180)
210            !------------------------------------------------------------------
211
212            DO ji = 1, inpfiles(jj)%nobs 
213
214               IF ( inpfiles(jj)%plam(ji) < -180. ) &
215                  &   inpfiles(jj)%plam(ji) = inpfiles(jj)%plam(ji) + 360.
216
217               IF ( inpfiles(jj)%plam(ji) >  180. ) &
218                  &   inpfiles(jj)%plam(ji) = inpfiles(jj)%plam(ji) - 360.
219
220            END DO
221
222            !------------------------------------------------------------------
223            !  Calculate the date  (change eventually)
224            !------------------------------------------------------------------
225            cl_refdate=inpfiles(jj)%cdjuldref(1:8)
226            READ(cl_refdate,'(I8)') irefdate(jj)
227           
228            CALL ddatetoymdhms( ddobsini, iyea, imon, iday, ihou, imin, isec )
229            CALL greg2jul( isec, imin, ihou, iday, imon, iyea, djulini(jj), &
230               &           krefdate = irefdate(jj) )
231            CALL ddatetoymdhms( ddobsend, iyea, imon, iday, ihou, imin, isec )
232            CALL greg2jul( isec, imin, ihou, iday, imon, iyea, djulend(jj), &
233               &           krefdate = irefdate(jj) )
234            IF ( inpfiles(jj)%nobs > 0 ) THEN
235               inpfiles(jj)%iproc = -1
236               inpfiles(jj)%iobsi = -1
237               inpfiles(jj)%iobsj = -1
238            ENDIF
239            inowin = 0
240            DO ji = 1, inpfiles(jj)%nobs
241               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
242                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
243                  inowin = inowin + 1
244               ENDIF
245            END DO
246            ALLOCATE( zlam(inowin)  )
247            ALLOCATE( zphi(inowin)  )
248            ALLOCATE( iobsi(inowin) )
249            ALLOCATE( iobsj(inowin) )
250            ALLOCATE( iproc(inowin) )
251            inowin = 0
252            DO ji = 1, inpfiles(jj)%nobs
253               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
254                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
255                  inowin = inowin + 1
256                  zlam(inowin) = inpfiles(jj)%plam(ji)
257                  zphi(inowin) = inpfiles(jj)%pphi(ji)
258               ENDIF
259            END DO
260
261            CALL obs_grid_search( inowin, zlam, zphi, iobsi, iobsj, iproc, 'T' )
262
263            inowin = 0
264            DO ji = 1, inpfiles(jj)%nobs
265               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
266                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
267                  inowin = inowin + 1
268                  inpfiles(jj)%iproc(ji,1) = iproc(inowin)
269                  inpfiles(jj)%iobsi(ji,1) = iobsi(inowin)
270                  inpfiles(jj)%iobsj(ji,1) = iobsj(inowin)
271               ENDIF
272            END DO
273            DEALLOCATE( zlam, zphi, iobsi, iobsj, iproc )
274
275            DO ji = 1, inpfiles(jj)%nobs
276               IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
277                  & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
278                  IF ( nproc == 0 ) THEN
279                     IF ( inpfiles(jj)%iproc(ji,1) >  nproc ) CYCLE
280                  ELSE
281                     IF ( inpfiles(jj)%iproc(ji,1) /= nproc ) CYCLE
282                  ENDIF
283                  llvalprof = .FALSE.
284                  IF ( .NOT. BTEST(inpfiles(jj)%ivlqc(1,ji,1),2) ) THEN
285                     iobs = iobs + 1
286                  ENDIF
287               ENDIF
288            END DO
289
290         ENDIF
291
292      END DO seaice_files
293
294      !-----------------------------------------------------------------------
295      ! Get the time ordered indices of the input data
296      !-----------------------------------------------------------------------
297
298      !---------------------------------------------------------------------
299      !  Loop over input data files to count total number of profiles
300      !---------------------------------------------------------------------
301      iobstot = 0
302      DO jj = 1, inobf
303         DO ji = 1, inpfiles(jj)%nobs
304            IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
305               & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
306               iobstot = iobstot + 1
307            ENDIF
308         END DO
309      END DO
310
311      ALLOCATE( iindx(iobstot), ifileidx(iobstot), &
312         &      iseaiceidx(iobstot), zdat(iobstot) )
313      jk = 0
314      DO jj = 1, inobf
315         DO ji = 1, inpfiles(jj)%nobs
316            IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND. &
317               & ( inpfiles(jj)%ptim(ji) <= djulend(jj) )       ) THEN
318               jk = jk + 1
319               ifileidx(jk) = jj
320               iseaiceidx(jk) = ji
321               zdat(jk)     = inpfiles(jj)%ptim(ji)
322            ENDIF
323         END DO
324      END DO
325      CALL sort_dp_indx( iobstot, &
326         &               zdat,     &
327         &               iindx   )
328     
329      CALL obs_surf_alloc( seaicedata, iobs, & 
330                           kvars, kextr, kstp, jpi, jpj )
331     
332      ! * Read obs/positions, QC, all variable and assign to seaicedata
333 
334      iobs = 0
335
336      ityp   (:) = 0
337      itypmpp(:) = 0
338
339      ioserrcount=0     
340
341      DO jk = 1, iobstot
342         
343         jj = ifileidx(iindx(jk))
344         ji = iseaiceidx(iindx(jk))
345         IF ( ( inpfiles(jj)%ptim(ji) >  djulini(jj) ) .AND.  &
346            & ( inpfiles(jj)%ptim(ji) <= djulend(jj) ) ) THEN
347           
348            IF ( nproc == 0 ) THEN
349               IF ( inpfiles(jj)%iproc(ji,1) >  nproc ) CYCLE
350            ELSE
351               IF ( inpfiles(jj)%iproc(ji,1) /= nproc ) CYCLE
352            ENDIF
353           
354            ! Set observation information
355           
356            IF ( .NOT. BTEST(inpfiles(jj)%ivlqc(1,ji,1),2) ) THEN
357
358               iobs = iobs + 1
359
360               CALL jul2greg( isec,                   &
361                  &           imin,                   &
362                  &           ihou,                   &
363                  &           iday,                   &
364                  &           imon,                   &
365                  &           iyea,                   &
366                  &           inpfiles(jj)%ptim(ji), &
367                  &           irefdate(jj) )
368
369
370               ! seaice time coordinates
371               seaicedata%nyea(iobs) = iyea
372               seaicedata%nmon(iobs) = imon
373               seaicedata%nday(iobs) = iday
374               seaicedata%nhou(iobs) = ihou
375               seaicedata%nmin(iobs) = imin
376               
377               ! seaice space coordinates
378               seaicedata%rlam(iobs) = inpfiles(jj)%plam(ji)
379               seaicedata%rphi(iobs) = inpfiles(jj)%pphi(ji)
380
381               ! Coordinate search parameters
382               seaicedata%mi  (iobs) = inpfiles(jj)%iobsi(ji,1)
383               seaicedata%mj  (iobs) = inpfiles(jj)%iobsj(ji,1)
384               
385               ! Instrument type
386               READ( inpfiles(jj)%cdtyp(ji), '(I4)', IOSTAT = ios, ERR = 901 ) itype
387901            IF ( ios /= 0 ) THEN
388                  IF (ioserrcount == 0) CALL ctl_warn ( 'Problem converting an instrument type to integer. Setting type to zero' ) 
389                  ioserrcount = ioserrcount + 1
390                  itype = 0
391               ENDIF
392               seaicedata%ntyp(iobs) = itype
393               IF ( itype < iseaicemaxtype + 1 ) THEN
394                  ityp(itype+1) = ityp(itype+1) + 1
395               ELSE
396                  IF(lwp)WRITE(numout,*)'WARNING:Increase iseaicemaxtype in ',&
397                     &                  cpname
398               ENDIF
399
400               ! Bookkeeping data to match observations
401               seaicedata%nsidx(iobs) = iobs
402               seaicedata%nsfil(iobs) = iindx(jk)
403
404               ! QC flags
405               seaicedata%nqc(iobs) = inpfiles(jj)%ivqc(ji,1)
406
407               ! Observed value
408               seaicedata%robs(iobs,1) = inpfiles(jj)%pob(1,ji,1)
409
410
411               ! Model and MDT is set to fbrmdi unless read from file
412               IF ( ldmod ) THEN
413                  seaicedata%rmod(iobs,1) = inpfiles(jj)%padd(1,ji,1,1)
414               ELSE
415                  seaicedata%rmod(iobs,1) = fbrmdi
416               ENDIF
417            ENDIF
418         ENDIF
419
420      END DO
421
422      !-----------------------------------------------------------------------
423      ! Sum up over processors
424      !-----------------------------------------------------------------------
425     
426      CALL obs_mpp_sum_integer( iobs, iobsmpp )
427     
428      !-----------------------------------------------------------------------
429      ! Output number of observations.
430      !-----------------------------------------------------------------------
431      IF (lwp) THEN
432
433         WRITE(numout,*)
434         WRITE(numout,'(1X,A)')'Seaice data types'
435         WRITE(numout,'(1X,A)')'-----------------'
436         DO jj = 1,8
437            IF ( itypmpp(jj) > 0 ) THEN
438               WRITE(numout,'(1X,A4,I4,A3,I10)')'Type ', jj,' = ',itypmpp(jj)
439            ENDIF
440         END DO
441         WRITE(numout,'(1X,A50)')'--------------------------------------------------'
442         WRITE(numout,'(1X,A40,I10)')'Total                                 = ',iobsmpp
443         WRITE(numout,*)
444
445      ENDIF
446
447      !-----------------------------------------------------------------------
448      ! Deallocate temporary data
449      !-----------------------------------------------------------------------
450      DEALLOCATE( ifileidx, iseaiceidx, zdat )
451
452      !-----------------------------------------------------------------------
453      ! Deallocate input data
454      !-----------------------------------------------------------------------
455      DO jj = 1, inobf
456         CALL dealloc_obfbdata( inpfiles(jj) )
457      END DO
458      DEALLOCATE( inpfiles )
459
460   END SUBROUTINE obs_rea_seaice
461
462END MODULE obs_read_seaice
463
Note: See TracBrowser for help on using the repository browser.