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.
sao_read.F90 in branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/NEMO/SAO_SRC – NEMO

source: branches/2014/dev_r4650_UKMO14.12_STAND_ALONE_OBSOPER/NEMOGCM/NEMO/SAO_SRC/sao_read.F90 @ 8574

Last change on this file since 8574 was 5063, checked in by andrewryan, 9 years ago

gross simplification of stand alone observation operator

File size: 6.5 KB
RevLine 
[4848]1MODULE sao_read
[4110]2   !!==================================================================
[4848]3   !!                    *** MODULE sao_read ***
[4846]4   !! Read routines : I/O for Stand Alone Observation operator
[4110]5   !!==================================================================
6   USE mppini
7   USE lib_mpp
8   USE in_out_manager
9   USE par_kind, ONLY: lc
10   USE netcdf
11   USE oce,     ONLY: tsn, sshn
12   USE dom_oce, ONLY: nlci, nlcj, nimpp, njmpp, tmask
13   USE par_oce, ONLY: jpi, jpj, jpk
14   USE obs_fbm, ONLY: fbimdi, fbrmdi, fbsp, fbdp
[4849]15   USE sao_data
[4030]16
[4110]17   IMPLICIT NONE
18   PRIVATE
[4030]19
[4848]20   PUBLIC sao_rea_dri
[4030]21
22CONTAINS
[4848]23   SUBROUTINE sao_rea_dri(kfile)
[4084]24      !!------------------------------------------------------------------------
[4848]25      !!             *** sao_rea_dri ***
[4084]26      !!
27      !! Purpose : To choose appropriate read method
[5063]28      !! Method  :
[4084]29      !!
30      !! Author  : A. Ryan Oct 2013
31      !!
32      !!------------------------------------------------------------------------
[4048]33      INTEGER, INTENT(IN) :: &
34              & kfile         !: File number
[4030]35      CHARACTER(len=lc) :: &
[5063]36              & cdfilename    !: File name
[4030]37      INTEGER :: &
[5063]38              & kindex        !: File index to read
39
[4846]40      cdfilename = TRIM(sao_files(kfile))
41      kindex = nn_sao_idx(kfile)
[5063]42      CALL sao_read_file(TRIM(cdfilename), kindex)
[4048]43
[4848]44   END SUBROUTINE sao_rea_dri
[4030]45
[4848]46   SUBROUTINE sao_read_file(filename, ifcst)
[4084]47      !!------------------------------------------------------------------------
[4848]48      !!             *** sao_read_file ***
[4084]49      !!
50      !! Purpose : To fill tn and sn with dailymean field from netcdf files
51      !! Method  : Use subdomain indices to create start and count matrices
52      !!           for netcdf read.
53      !!
54      !! Author  : A. Ryan Oct 2010
55      !!------------------------------------------------------------------------
[4030]56
57      INTEGER,          INTENT(IN) :: ifcst
58      CHARACTER(len=*), INTENT(IN) :: filename
59      INTEGER                      :: ncid, &
60                                    & varid,&
61                                    & istat,&
62                                    & ntimes,&
63                                    & tdim, &
64                                    & xdim, &
65                                    & ydim, &
66                                    & zdim
67      INTEGER                      :: ii, ij, ik
68      INTEGER, DIMENSION(4)        :: start_n, &
69                                    & count_n
70      INTEGER, DIMENSION(3)        :: start_s, &
71                                    & count_s
72      REAL(fbdp), DIMENSION(:,:,:),ALLOCATABLE :: temp_tn, &
73                                              & temp_sn
74      REAL(fbdp), DIMENSION(:,:),  ALLOCATABLE :: temp_sshn
75      REAL(fbdp)                     :: fill_val
76
77      ! DEBUG
78      INTEGER :: istage
79
80      IF (TRIM(filename) == 'nofile') THEN
81         tsn(:,:,:,:) = fbrmdi
[5063]82         sshn(:,:) = fbrmdi
[4030]83      ELSE
[4108]84         WRITE(numout,*) "Opening :", TRIM(filename)
[4030]85         ! Open Netcdf file to find dimension id
[4031]86         istat = nf90_open(path=TRIM(filename), mode=nf90_nowrite, ncid=ncid)
[4030]87         IF ( istat /= nf90_noerr ) THEN
[4108]88             WRITE(numout,*) "WARNING: Could not open ", trim(filename)
89             WRITE(numout,*) "ERROR: ", nf90_strerror(istat)
[4030]90         ENDIF
91         istat = nf90_inq_dimid(ncid,'x',xdim)
92         istat = nf90_inq_dimid(ncid,'y',ydim)
93         istat = nf90_inq_dimid(ncid,'deptht',zdim)
94         istat = nf90_inq_dimid(ncid,'time_counter',tdim)
95         istat = nf90_inquire_dimension(ncid, tdim, len=ntimes)
[5063]96         IF (ifcst .LE. ntimes) THEN
[4030]97            ! Allocate temporary temperature array
98            ALLOCATE(temp_tn(nlci,nlcj,jpk))
99            ALLOCATE(temp_sn(nlci,nlcj,jpk))
100            ALLOCATE(temp_sshn(nlci,nlcj))
[5063]101
[4030]102            ! Set temp_tn, temp_sn to 0.
103            temp_tn(:,:,:) = fbrmdi
104            temp_sn(:,:,:) = fbrmdi
105            temp_sshn(:,:) = fbrmdi
[5063]106
[4030]107            ! Create start and count arrays
108            start_n = (/ nimpp, njmpp, 1,   ifcst /)
109            count_n = (/ nlci,  nlcj,  jpk, 1     /)
110            start_s = (/ nimpp, njmpp, ifcst /)
111            count_s = (/ nlci,  nlcj,  1     /)
[5063]112
[4030]113            ! Read information into temporary arrays
114            ! retrieve varid and read in temperature
115            istat = nf90_inq_varid(ncid,'votemper',varid)
116            istat = nf90_get_att(ncid, varid, '_FillValue', fill_val)
117            istat = nf90_get_var(ncid, varid, temp_tn, start_n, count_n)
118            WHERE(temp_tn(:,:,:) == fill_val) temp_tn(:,:,:) = fbrmdi
[5063]119
[4030]120            ! retrieve varid and read in salinity
121            istat = nf90_inq_varid(ncid,'vosaline',varid)
122            istat = nf90_get_att(ncid, varid, '_FillValue', fill_val)
123            istat = nf90_get_var(ncid, varid, temp_sn, start_n, count_n)
124            WHERE(temp_sn(:,:,:) == fill_val) temp_sn(:,:,:) = fbrmdi
[5063]125
[4030]126            ! retrieve varid and read in SSH
127            istat = nf90_inq_varid(ncid,'sossheig',varid)
128            IF (istat /= nf90_noerr) THEN
129               ! Altimeter bias
130               istat = nf90_inq_varid(ncid,'altbias',varid)
131            END IF
[5063]132
[4030]133            istat = nf90_get_att(ncid, varid, '_FillValue', fill_val)
134            istat = nf90_get_var(ncid, varid, temp_sshn, start_s, count_s)
135            WHERE(temp_sshn(:,:) == fill_val) temp_sshn(:,:) = fbrmdi
[5063]136
[4030]137            ! Initialise tsn, sshn to fbrmdi
138            tsn(:,:,:,:) = fbrmdi
[5063]139            sshn(:,:) = fbrmdi
[4030]140
141            ! Mask out missing data index
142            tsn(1:nlci,1:nlcj,1:jpk,1) = temp_tn(:,:,:) * tmask(1:nlci,1:nlcj,1:jpk)
143            tsn(1:nlci,1:nlcj,1:jpk,2) = temp_sn(:,:,:) * tmask(1:nlci,1:nlcj,1:jpk)
144            sshn(1:nlci,1:nlcj)        = temp_sshn(:,:) * tmask(1:nlci,1:nlcj,1)
145
146            ! Remove halo from tmask, tsn, sshn to prevent double obs counting
147            IF (jpi > nlci) THEN
148                tmask(nlci+1:,:,:) = 0
149                tsn(nlci+1:,:,:,1) = 0
150                tsn(nlci+1:,:,:,2) = 0
151                sshn(nlci+1:,:) = 0
152            END IF
153            IF (jpj > nlcj) THEN
154                tmask(:,nlcj+1:,:) = 0
155                tsn(:,nlcj+1:,:,1) = 0
156                tsn(:,nlcj+1:,:,2) = 0
157                sshn(:,nlcj+1:) = 0
158            END IF
159
160            ! Deallocate arrays
161            DEALLOCATE(temp_tn, temp_sn, temp_sshn)
[5063]162         ELSE
[4030]163            ! Mark all as missing data
164            tsn(:,:,:,:) = fbrmdi
[5063]165            sshn(:,:) = fbrmdi
[4030]166         ENDIF
167         ! Close netcdf file
[4108]168         WRITE(numout,*) "Closing :", TRIM(filename)
[4030]169         istat = nf90_close(ncid)
170      END IF
[4848]171   END SUBROUTINE sao_read_file
[5063]172END MODULE sao_read
Note: See TracBrowser for help on using the repository browser.