123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548 |
- MODULE obs_read_sla
- !!======================================================================
- !! *** MODULE obs_read_sla ***
- !! Observation diagnostics: Read the along track SLA data from
- !! the AVISO/CLS database or any SLA data
- !! from feedback files
- !!======================================================================
- !!----------------------------------------------------------------------
- !! obs_rea_sla : Driver for reading SLA data from the AVISO/CLS/feedback
- !!----------------------------------------------------------------------
- !! * Modules used
- USE par_kind ! Precision variables
- USE in_out_manager ! I/O manager
- USE dom_oce ! Ocean space and time domain variables
- USE obs_mpp ! MPP support routines for observation diagnostics
- USE julian ! Julian date routines
- USE obs_utils ! Observation operator utility functions
- USE obs_grid ! Grid search
- USE obs_sort ! Sorting observation arrays
- USE obs_surf_def ! Surface observation definitions
- USE obs_types ! Observation type definitions
- USE obs_sla_io ! I/O for sla files
- USE netcdf ! NetCDF library
- IMPLICIT NONE
- !! * Routine accessibility
- PRIVATE
- PUBLIC obs_rea_sla ! Read the SLA observations from the AVISO/SLA database
- !!----------------------------------------------------------------------
- !! NEMO/OPA 3.3 , NEMO Consortium (2010)
- !! $Id: obs_read_sla.F90 4990 2014-12-15 16:42:49Z timgraham $
- !! Software governed by the CeCILL licence (NEMOGCM/NEMO_CeCILL.txt)
- !!----------------------------------------------------------------------
- CONTAINS
- SUBROUTINE obs_rea_sla( kformat, &
- & sladata, knumfiles, cfilenames, &
- & kvars, kextr, kstp, ddobsini, ddobsend, &
- & ldignmis, ldmod, ldobstd )
- !!---------------------------------------------------------------------
- !!
- !! *** ROUTINE obs_rea_sla ***
- !!
- !! ** Purpose : Read from file the SLA data
- !!
- !! ** Method : Depending on kformat either AVISO or
- !! feedback data files are read
- !!
- !! ** Action :
- !!
- !!
- !! History :
- !! ! : 2009-01 (K. Mogensen) Initial version based on old versions
- !!----------------------------------------------------------------------
- !! * Modules used
- !! * Arguments
- INTEGER :: kformat ! Format of input data
- ! ! 0: Feedback
- ! ! 1: AVISO
- TYPE(obs_surf), INTENT(INOUT) :: sladata ! SLA data to be read
- INTEGER, INTENT(IN) :: knumfiles ! Number of files to read in
- CHARACTER(LEN=128), INTENT(IN) :: &
- & cfilenames(knumfiles) ! File names to read in
- INTEGER, INTENT(IN) :: kvars ! Number of variables in sladata
- INTEGER, INTENT(IN) :: kextr ! Number of extra fields for each var in sladata
- INTEGER, INTENT(IN) :: kstp ! Ocean time-step index
- LOGICAL, INTENT(IN) :: ldignmis ! Ignore missing files
- LOGICAL, INTENT(IN) :: ldmod ! Initialize model from input data
- LOGICAL, INTENT(INOUT), optional :: &
- & ldobstd ! Read observation standard deviation from fb. file
- REAL(KIND=dp), INTENT(IN) :: ddobsini ! Obs. ini time in YYYYMMDD.HHMMSS
- REAL(KIND=dp), INTENT(IN) :: ddobsend ! Obs. end time in YYYYMMDD.HHMMSS
-
- !! * Local declarations
- CHARACTER(LEN=11), PARAMETER :: cpname='obs_rea_sla'
- INTEGER :: ji
- INTEGER :: jj
- INTEGER :: jk
- INTEGER :: iflag
- INTEGER :: inobf
- INTEGER :: i_file_id
- INTEGER :: inowin
- INTEGER :: iyea
- INTEGER :: imon
- INTEGER :: iday
- INTEGER :: ihou
- INTEGER :: imin
- INTEGER :: isec
- INTEGER, DIMENSION(knumfiles) :: &
- & irefdate
- INTEGER :: iobsmpp
- INTEGER, DIMENSION(imaxmissions+1) :: &
- & ityp, &
- & itypmpp
- INTEGER, DIMENSION(:), ALLOCATABLE :: &
- & iobsi, &
- & iobsj, &
- & iproc, &
- & iindx, &
- & ifileidx, &
- & islaidx
- INTEGER :: itype
- REAL(wp), DIMENSION(:), ALLOCATABLE :: &
- & zphi, &
- & zlam
- real(wp), DIMENSION(:), ALLOCATABLE :: &
- & zdat
- LOGICAL :: llvalprof
- LOGICAL :: llobstd
- TYPE(obfbdata), POINTER, DIMENSION(:) :: &
- & inpfiles
- real(wp), DIMENSION(knumfiles) :: &
- & djulini, &
- & djulend
- INTEGER, DIMENSION(knumfiles) :: &
- & iobspos, &
- & iobcpos
- INTEGER :: iobs
- INTEGER :: iobstot
- INTEGER :: ios
- INTEGER :: ioserrcount
- CHARACTER(len=8) :: cl_refdate
-
- ! Local initialization
- iobs = 0
- IF ( PRESENT(ldobstd) ) THEN
- IF (.NOT.ldmod) THEN
- llobstd = .false.
- ELSE
- llobstd = ldobstd
- ENDIF
- ELSE
- llobstd = .FALSE.
- ENDIF
-
- !-----------------------------------------------------------------------
- ! Check that the model part is just with feedback data files
- !-----------------------------------------------------------------------
- IF ( ldmod .AND. ( kformat /= 0 ) ) THEN
- CALL ctl_stop( 'Model can only be read from feedback data' )
- RETURN
- ENDIF
- !-----------------------------------------------------------------------
- ! Check that the prescribed obs err is just with feedback data files
- !-----------------------------------------------------------------------
- IF ( llobstd .AND. ( kformat /= 0 ) ) THEN
- CALL ctl_stop( 'Observation error can only be read from feedback files' )
- RETURN
- ENDIF
- !-----------------------------------------------------------------------
- ! Count the number of files needed and allocate the obfbdata type
- !-----------------------------------------------------------------------
-
- inobf = knumfiles
-
- ALLOCATE( inpfiles(inobf) )
- sla_files : DO jj = 1, inobf
-
- !---------------------------------------------------------------------
- ! Prints
- !---------------------------------------------------------------------
- IF(lwp) THEN
- WRITE(numout,*)
- WRITE(numout,*) ' obs_rea_sla : Reading from file = ', &
- & TRIM( TRIM( cfilenames(jj) ) )
- WRITE(numout,*) ' ~~~~~~~~~~~'
- WRITE(numout,*)
- ENDIF
- !---------------------------------------------------------------------
- ! Initialization: Open file and get dimensions only
- !---------------------------------------------------------------------
-
- iflag = nf90_open( TRIM( TRIM( cfilenames(jj) ) ), nf90_nowrite, &
- & i_file_id )
-
- IF ( iflag /= nf90_noerr ) THEN
- IF ( ldignmis ) THEN
- inpfiles(jj)%nobs = 0
- CALL ctl_warn( 'File ' // TRIM( TRIM( cfilenames(jj) ) ) // &
- & ' not found' )
- ELSE
- CALL ctl_stop( 'File ' // TRIM( TRIM( cfilenames(jj) ) ) // &
- & ' not found' )
- ENDIF
- ELSE
-
- !------------------------------------------------------------------
- ! Close the file since it is opened in read_proffile
- !------------------------------------------------------------------
-
- iflag = nf90_close( i_file_id )
- !------------------------------------------------------------------
- ! Read the profile file into inpfiles
- !------------------------------------------------------------------
- IF ( kformat == 0 ) THEN
- CALL init_obfbdata( inpfiles(jj) )
- IF(lwp) THEN
- WRITE(numout,*)
- WRITE(numout,*)'Reading from feedback file :', &
- & TRIM( cfilenames(jj) )
- ENDIF
- CALL read_obfbdata( TRIM( cfilenames(jj) ), inpfiles(jj), &
- & ldgrid = .TRUE. )
- IF ( inpfiles(jj)%nvar < 1 ) THEN
- CALL ctl_stop( 'Feedback format error' )
- RETURN
- ENDIF
- IF ( TRIM(inpfiles(jj)%cname(1)) /= 'SLA' ) THEN
- CALL ctl_stop( 'Feedback format error' )
- RETURN
- ENDIF
- IF ( ldmod .AND. ( ( inpfiles(jj)%nadd == 0 ) .OR.&
- & ( inpfiles(jj)%next == 0 ) ) ) THEN
- CALL ctl_stop( 'Model not in input data' )
- RETURN
- ENDIF
- ELSEIF ( kformat == 1) THEN
- CALL read_avisofile( TRIM( cfilenames(jj) ), inpfiles(jj), &
- & numout, lwp, .TRUE. )
- ELSE
- CALL ctl_stop( 'File format unknown' )
- ENDIF
- !------------------------------------------------------------------
- ! Change longitude (-180,180)
- !------------------------------------------------------------------
- DO ji = 1, inpfiles(jj)%nobs
- IF ( inpfiles(jj)%plam(ji) < -180. ) &
- & inpfiles(jj)%plam(ji) = inpfiles(jj)%plam(ji) + 360.
- IF ( inpfiles(jj)%plam(ji) > 180. ) &
- & inpfiles(jj)%plam(ji) = inpfiles(jj)%plam(ji) - 360.
- END DO
- !------------------------------------------------------------------
- ! Calculate the date (change eventually)
- !------------------------------------------------------------------
- cl_refdate=inpfiles(jj)%cdjuldref(1:8)
- READ(cl_refdate,'(I8)') irefdate(jj)
-
- CALL ddatetoymdhms( ddobsini, iyea, imon, iday, ihou, imin, isec )
- CALL greg2jul( isec, imin, ihou, iday, imon, iyea, djulini(jj), &
- & krefdate = irefdate(jj) )
- CALL ddatetoymdhms( ddobsend, iyea, imon, iday, ihou, imin, isec )
- CALL greg2jul( isec, imin, ihou, iday, imon, iyea, djulend(jj), &
- & krefdate = irefdate(jj) )
- IF ( inpfiles(jj)%nobs > 0 ) THEN
- inpfiles(jj)%iproc = -1
- inpfiles(jj)%iobsi = -1
- inpfiles(jj)%iobsj = -1
- ENDIF
- inowin = 0
- DO ji = 1, inpfiles(jj)%nobs
- IF ( inpfiles(jj)%ioqc(ji) > 2 ) CYCLE
- IF ( inpfiles(jj)%ivqc(ji,1) > 2 ) CYCLE
- IF ( ( inpfiles(jj)%ptim(ji) > djulini(jj) ) .AND. &
- & ( inpfiles(jj)%ptim(ji) <= djulend(jj) ) ) THEN
- inowin = inowin + 1
- ENDIF
- END DO
- ALLOCATE( zlam(inowin) )
- ALLOCATE( zphi(inowin) )
- ALLOCATE( iobsi(inowin) )
- ALLOCATE( iobsj(inowin) )
- ALLOCATE( iproc(inowin) )
- inowin = 0
- DO ji = 1, inpfiles(jj)%nobs
- IF ( inpfiles(jj)%ioqc(ji) > 2 ) CYCLE
- IF ( inpfiles(jj)%ivqc(ji,1) > 2 ) CYCLE
- IF ( ( inpfiles(jj)%ptim(ji) > djulini(jj) ) .AND. &
- & ( inpfiles(jj)%ptim(ji) <= djulend(jj) ) ) THEN
- inowin = inowin + 1
- zlam(inowin) = inpfiles(jj)%plam(ji)
- zphi(inowin) = inpfiles(jj)%pphi(ji)
- ENDIF
- END DO
- CALL obs_grid_search( inowin, zlam, zphi, iobsi, iobsj, iproc, 'T' )
- inowin = 0
- DO ji = 1, inpfiles(jj)%nobs
- IF ( inpfiles(jj)%ioqc(ji) > 2 ) CYCLE
- IF ( inpfiles(jj)%ivqc(ji,1) > 2 ) CYCLE
- IF ( ( inpfiles(jj)%ptim(ji) > djulini(jj) ) .AND. &
- & ( inpfiles(jj)%ptim(ji) <= djulend(jj) ) ) THEN
- inowin = inowin + 1
- inpfiles(jj)%iproc(ji,1) = iproc(inowin)
- inpfiles(jj)%iobsi(ji,1) = iobsi(inowin)
- inpfiles(jj)%iobsj(ji,1) = iobsj(inowin)
- ENDIF
- END DO
- DEALLOCATE( zlam, zphi, iobsi, iobsj, iproc )
- DO ji = 1, inpfiles(jj)%nobs
- IF ( inpfiles(jj)%ioqc(ji) > 2 ) CYCLE
- IF ( inpfiles(jj)%ivqc(ji,1) > 2 ) CYCLE
- IF ( ( inpfiles(jj)%ptim(ji) > djulini(jj) ) .AND. &
- & ( inpfiles(jj)%ptim(ji) <= djulend(jj) ) ) THEN
- IF ( nproc == 0 ) THEN
- IF ( inpfiles(jj)%iproc(ji,1) > nproc ) CYCLE
- ELSE
- IF ( inpfiles(jj)%iproc(ji,1) /= nproc ) CYCLE
- ENDIF
- llvalprof = .FALSE.
- IF ( ( inpfiles(jj)%ivlqc(1,ji,1) == 1 ) .OR. &
- & ( inpfiles(jj)%ivlqc(1,ji,1) == 2 ) ) THEN
- iobs = iobs + 1
- ENDIF
- ENDIF
- END DO
- ENDIF
-
- END DO sla_files
- IF (llobstd) THEN
-
- DO jj = 1, inobf
- iobspos(jj) = -1
- iobcpos(jj) = -1
- DO ji = 1,inpfiles(jj)%nadd
- IF ( TRIM(inpfiles(jj)%caddname(ji)) == 'OSTD' ) THEN
- iobspos(jj)=ji
- ENDIF
- IF ( TRIM(inpfiles(jj)%caddname(ji)) == 'OCNT' ) THEN
- iobcpos(jj)=ji
- ENDIF
- END DO
- END DO
- llobstd = ( ( MINVAL(iobspos) > 0 ) .AND. ( MINVAL(iobcpos) > 0 ) )
- IF (llobstd) THEN
- IF (lwp) WRITE(numout,*)'SLA superobs information present.'
- ELSE
- IF (lwp) WRITE(numout,*)'SLA superobs information not present.'
- ENDIF
- ENDIF
-
- !-----------------------------------------------------------------------
- ! Get the time ordered indices of the input data
- !-----------------------------------------------------------------------
- !---------------------------------------------------------------------
- ! Loop over input data files to count total number of profiles
- !---------------------------------------------------------------------
- iobstot = 0
- DO jj = 1, inobf
- DO ji = 1, inpfiles(jj)%nobs
- IF ( inpfiles(jj)%ioqc(ji) > 2 ) CYCLE
- IF ( inpfiles(jj)%ivqc(ji,1) > 2 ) CYCLE
- IF ( ( inpfiles(jj)%ptim(ji) > djulini(jj) ) .AND. &
- & ( inpfiles(jj)%ptim(ji) <= djulend(jj) ) ) THEN
- iobstot = iobstot + 1
- ENDIF
- END DO
- END DO
- ALLOCATE( iindx(iobstot), ifileidx(iobstot), &
- & islaidx(iobstot), zdat(iobstot) )
- jk = 0
- DO jj = 1, inobf
- DO ji = 1, inpfiles(jj)%nobs
- IF ( inpfiles(jj)%ioqc(ji) > 2 ) CYCLE
- IF ( inpfiles(jj)%ivqc(ji,1) > 2 ) CYCLE
- IF ( ( inpfiles(jj)%ptim(ji) > djulini(jj) ) .AND. &
- & ( inpfiles(jj)%ptim(ji) <= djulend(jj) ) ) THEN
- jk = jk + 1
- ifileidx(jk) = jj
- islaidx(jk) = ji
- zdat(jk) = inpfiles(jj)%ptim(ji)
- ENDIF
- END DO
- END DO
- CALL sort_dp_indx( iobstot, &
- & zdat, &
- & iindx )
-
- CALL obs_surf_alloc( sladata, iobs, kvars, kextr, kstp, jpi, jpj )
-
- ! * Read obs/positions, QC, all variable and assign to sladata
-
- iobs = 0
- ityp (:) = 0
- itypmpp(:) = 0
- ioserrcount = 0
-
- DO jk = 1, iobstot
-
- jj = ifileidx(iindx(jk))
- ji = islaidx(iindx(jk))
- IF ( inpfiles(jj)%ioqc(ji) > 2 ) CYCLE
- IF ( inpfiles(jj)%ivqc(ji,1) > 2 ) CYCLE
- IF ( ( inpfiles(jj)%ptim(ji) > djulini(jj) ) .AND. &
- & ( inpfiles(jj)%ptim(ji) <= djulend(jj) ) ) THEN
-
- IF ( nproc == 0 ) THEN
- IF ( inpfiles(jj)%iproc(ji,1) > nproc ) CYCLE
- ELSE
- IF ( inpfiles(jj)%iproc(ji,1) /= nproc ) CYCLE
- ENDIF
-
- ! Set observation information
-
- IF ( ( inpfiles(jj)%ivlqc(1,ji,1) == 1 ) .OR. &
- & ( inpfiles(jj)%ivlqc(1,ji,1) == 2 ) ) THEN
- iobs = iobs + 1
- CALL jul2greg( isec, &
- & imin, &
- & ihou, &
- & iday, &
- & imon, &
- & iyea, &
- & inpfiles(jj)%ptim(ji), &
- & irefdate(jj) )
- ! SLA time coordinates
- sladata%nyea(iobs) = iyea
- sladata%nmon(iobs) = imon
- sladata%nday(iobs) = iday
- sladata%nhou(iobs) = ihou
- sladata%nmin(iobs) = imin
-
- ! SLA space coordinates
- sladata%rlam(iobs) = inpfiles(jj)%plam(ji)
- sladata%rphi(iobs) = inpfiles(jj)%pphi(ji)
- ! Coordinate search parameters
- sladata%mi (iobs) = inpfiles(jj)%iobsi(ji,1)
- sladata%mj (iobs) = inpfiles(jj)%iobsj(ji,1)
-
- ! Instrument type
- READ( inpfiles(jj)%cdtyp(ji), '(I4)', IOSTAT = ios, ERR = 901 ) itype
- 901 IF ( ios /= 0 ) THEN
- IF (ioserrcount == 0) CALL ctl_warn ( 'Problem converting an instrument type to integer. Setting type to zero' )
- ioserrcount = ioserrcount + 1
- itype = 0
- ENDIF
- sladata%ntyp(iobs) = itype
- ityp(itype+1) = ityp(itype+1) + 1
- ! Identifier
- sladata%cwmo(iobs) = inpfiles(jj)%cdwmo(ji)
- ! Bookkeeping data to match observations
- sladata%nsidx(iobs) = iobs
- sladata%nsfil(iobs) = iindx(jk)
- ! QC flags
- sladata%nqc(iobs) = inpfiles(jj)%ivqc(ji,1)
- ! Observed value
- sladata%robs(iobs,1) = inpfiles(jj)%pob(1,ji,1)
- ! Model and MDT is set to fbrmdi unless read from file
- IF ( ldmod ) THEN
- sladata%rmod(iobs,1) = inpfiles(jj)%padd(1,ji,1,1)
- sladata%rext(iobs,1) = inpfiles(jj)%padd(1,ji,2,1)
- sladata%rext(iobs,2) = inpfiles(jj)%pext(1,ji,1)
- IF (llobstd) THEN
- sladata%rext(iobs,3) = &
- & inpfiles(jj)%padd(1,ji,iobspos(jj),1)
- sladata%rext(iobs,4) = &
- & inpfiles(jj)%padd(1,ji,iobcpos(jj),1)
- ENDIF
- ELSE
- sladata%rmod(iobs,1) = fbrmdi
- sladata%rext(iobs,:) = fbrmdi
- ENDIF
- ENDIF
- ENDIF
- END DO
- !-----------------------------------------------------------------------
- ! Sum up over processors
- !-----------------------------------------------------------------------
-
- CALL obs_mpp_sum_integer( iobs, iobsmpp )
- CALL obs_mpp_sum_integers( ityp, itypmpp, imaxmissions + 1 )
-
- !-----------------------------------------------------------------------
- ! Output number of observations.
- !-----------------------------------------------------------------------
- IF (lwp) THEN
- WRITE(numout,*)
- WRITE(numout,'(1X,A)')'Altimeter satellites'
- WRITE(numout,'(1X,A)')'--------------------'
- DO jj = 1,8
- IF ( itypmpp(jj) > 0 ) THEN
- WRITE(numout,'(1X,A38,A2,I10)')calttyp(jj-1),'= ',itypmpp(jj)
- ENDIF
- END DO
- WRITE(numout,'(1X,A50)')'--------------------------------------------------'
- WRITE(numout,'(1X,A40,I10)')'Total = ',iobsmpp
- WRITE(numout,*)
- ENDIF
- !-----------------------------------------------------------------------
- ! Deallocate temporary data
- !-----------------------------------------------------------------------
- DEALLOCATE( ifileidx, islaidx, zdat )
- !-----------------------------------------------------------------------
- ! Deallocate input data
- !-----------------------------------------------------------------------
- DO jj = 1, inobf
- CALL dealloc_obfbdata( inpfiles(jj) )
- END DO
- DEALLOCATE( inpfiles )
- !-----------------------------------------------------------------------
- ! Reset ldobstd if the data is present
- !-----------------------------------------------------------------------
- IF ( PRESENT(ldobstd) ) THEN
- ldobstd = llobstd
- ENDIF
- END SUBROUTINE obs_rea_sla
- END MODULE obs_read_sla
|