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.
readcoordmesh.f90 in branches/2011/dev_r2802_MERCATOR10_diadct/NEMOGCM/TOOLS/SECTIONS_DIADCT/src – NEMO

source: branches/2011/dev_r2802_MERCATOR10_diadct/NEMOGCM/TOOLS/SECTIONS_DIADCT/src/readcoordmesh.f90 @ 2849

Last change on this file since 2849 was 2849, checked in by cbricaud, 13 years ago

tools to compute sections pathway

  • Property svn:executable set to *
File size: 5.3 KB
Line 
1MODULE readcoordmesh
2  !!=====================================================================
3  !!                       ***  MODULE  readcoordmesh  ***
4  !!
5  !! History: 2011: cbricaud Mercator-Ocean
6  !!
7  !!=====================================================================
8  !! * Modules used
9  USE netcdf
10  USE declarations
11
12  IMPLICIT NONE
13  PRIVATE
14 
15  PUBLIC  read_coord_mesh
16  PRIVATE read_ncdf
17
18CONTAINS
19
20  SUBROUTINE read_coord_mesh
21  !!---------------------------------------------------------------------
22  !!              ***  ROUTINE coord_mesh_read  ***
23  !!
24  !! ** Purpose :   Read a coordinate and a meshmask file in NetCDF format
25  !!---------------------------------------------------------------------     
26  !! * Local declarations
27  INTEGER                                 ::ji,jj
28
29  !!----------------------------------------------------------------------
30  PRINT*,'              '
31  PRINT*,'READ COORDINATES AND MESHMASK'
32  PRINT*,'-----------------------------'
33
34
35  !Allocate coordinate and meshmask array with domain size
36  ALLOCATE(glamt(jpi,jpj)) ; ALLOCATE(gphit(jpi,jpj))
37  ALLOCATE(glamf(jpi,jpj)) ; ALLOCATE(gphif(jpi,jpj))
38  ALLOCATE(e1t(jpi,jpj))   !; ALLOCATE(tmask(jpi,jpj,1))
39
40  !Read glamt
41  CALL read_ncdf(cdfile="coordinates.nc",cdvar="glamt",ksize=(/jpi,jpj,1,1/), &
42                   kstart=(/jpizoom,jpjzoom,1,1/),kcount=(/jpi,jpj,1,1/),ptab=glamt)
43
44  !Read gphit
45  CALL read_ncdf(cdfile="coordinates.nc",cdvar="gphit",ksize=(/jpi,jpj,1,1/), &
46                   kstart=(/jpizoom,jpjzoom,1,1/),kcount=(/jpi,jpj,1,1/),ptab=gphit)
47
48  !Read glamf
49  CALL read_ncdf(cdfile="coordinates.nc",cdvar="glamf",ksize=(/jpi,jpj,1,1/), &
50                   kstart=(/jpizoom,jpjzoom,1,1/),kcount=(/jpi,jpj,1,1/),ptab=glamf)
51
52  !Read gphif
53  CALL read_ncdf(cdfile="coordinates.nc",cdvar="gphif",ksize=(/jpi,jpj,1,1/), &
54                   kstart=(/jpizoom,jpjzoom,1,1/),kcount=(/jpi,jpj,1,1/),ptab=gphif)
55
56  !Read e1t
57  CALL read_ncdf(cdfile="coordinates.nc",cdvar="e1t",ksize=(/jpi,jpj,1,1/), &
58                   kstart=(/jpizoom,jpjzoom,1,1/),kcount=(/jpi,jpj,1,1/),ptab=e1t)
59
60!  tmask(:,:,:)=1
61
62  !compute mig and mjg arrays
63  ALLOCATE(mig(jpi))
64  ALLOCATE(mjg(jpj))
65  ! local domain indices ==> data domain indices
66  DO ji = 1, jpi ; mig(ji) = ji + jpizoom - 1 ; ENDDO
67  DO jj = 1, jpj ; mjg(jj) = jj + jpjzoom - 1 ; ENDDO
68
69 
70  END SUBROUTINE read_coord_mesh
71
72  SUBROUTINE read_ncdf(cdfile,cdvar,ksize,kstart,kcount,ptab)
73  !!----------------------------------------------------------------------
74  !!              ***  ROUTINE coord_mesh_read  ***
75  !!
76  !! ** Purpose :   Read a coordinate and a meshmask file in NetCDF format
77  !!----------------------------------------------------------------------
78  !! * Arguments
79  CHARACTER(*),        INTENT(IN)                                    :: cdfile
80  CHARACTER(*),        INTENT(IN)                                    :: cdvar
81  INTEGER,DIMENSION(4),INTENT(IN)                                    :: ksize
82  INTEGER,DIMENSION(4),INTENT(IN),OPTIONAL                           :: kstart,kcount
83  REAL(wp),DIMENSION(ksize(1),ksize(2),ksize(3),ksize(4)),INTENT(OUT),OPTIONAL:: ptab
84
85  !! * Local declarations
86  INTEGER                                 ::istatus,ncid,id_var,len
87  CHARACTER(len=30) :: clname , cdvar2
88
89  INTEGER :: idims
90  INTEGER,DIMENSION(3)::idimids 
91  !!----------------------------------------------------------------------
92  ptab=0.
93  PRINT*,'read ',TRIM(cdvar),' in ',TRIM(cdfile)
94 
95  !OPEN
96  !----
97  istatus=NF90_OPEN(TRIM(cdfile),nf90_nowrite,ncid)
98  IF( istatus/= NF90_NOERR )THEN
99      PRINT*,TRIM(cdfile),' not found.stop ' ; stop
100  ELSE
101      PRINT*,'     File dimensions: '
102      DO id_var=1,4
103         istatus=NF90_Inquire_Dimension(ncid,id_var,clname,len)
104         PRINT*,'       ',id_var,clname,len
105    ENDDO
106  ENDIF
107
108  !READ
109  !----
110  !search variable
111  istatus=NF90_INQ_VARID (ncid,TRIM(cdvar),id_var)
112  IF( istatus/=NF90_NOERR )THEN
113      PRINT*,TRIM(cdvar),' not found in ',TRIM(cdfile),'.stop';stop
114  ENDIF
115
116  !get variable
117  !------------
118  istatus=nf90_inquire_variable(ncid,id_var, cdvar2, ndims=idims, dimids=idimids)
119  IF ( PRESENT(kstart) .AND. PRESENT(kcount) )THEN 
120      istatus=NF90_GET_VAR(ncid,id_var,ptab,start=kstart,count=kcount)
121  ELSE
122      istatus=NF90_GET_VAR(ncid,id_var,ptab)
123  ENDIF
124
125  CALL ERR_HDL(istatus)
126
127  IF( istatus/=NF90_NOERR )THEN
128           PRINT*,'Problem for reading ',TRIM(cdvar),' in ',TRIM(cdfile);stop
129  ELSE
130      PRINT*,'     read ',TRIM(cdvar),' OK'
131  ENDIF
132
133  !CLOSE
134  !-----
135  istatus=NF90_CLOSE( ncid )
136  IF( istatus/=NF90_NOERR )THEN
137      PRINT*,'Problem for closing ',TRIM(cdfile);stop
138  ELSE
139      PRINT*,'     close ',TRIM(cdfile),' OK'
140  ENDIF
141
142
143  END SUBROUTINE read_ncdf
144
145  SUBROUTINE ERR_HDL(kstatus)
146  !! ----------------------------------------------------------
147  !!   ***  SUBROUTINE err_hdl
148  !!
149  !!   ** Purpose :  Error handle for NetCDF routine.
150  !!          Stop if kstatus indicates error conditions.
151  !!
152  !! History :
153  !!     Original: J.M. Molines (01/99)
154  !!
155  !! -----------------------------------------------------------
156  INTEGER, INTENT(in) ::  kstatus
157
158  !! -----------------------------------------------------------
159  IF( kstatus /=  NF90_NOERR ) THEN
160     PRINT *, 'ERROR in NETCDF routine, status=',kstatus
161     PRINT *,NF90_STRERROR(kstatus)
162     STOP
163  END IF
164
165  END SUBROUTINE ERR_HDL
166
167END MODULE readcoordmesh
Note: See TracBrowser for help on using the repository browser.