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 NEMO/trunk/src/SAO – NEMO

source: NEMO/trunk/src/SAO/sao_read.F90 @ 11238

Last change on this file since 11238 was 10069, checked in by nicolasmartin, 6 years ago

Fix mistakes of previous commit on SVN keywords property

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