source: branches/UKMO/r6232_tracer_advection/NEMOGCM/TOOLS/GRIDGEN/src/readwrite.f90 @ 9295

Last change on this file since 9295 was 9295, checked in by jcastill, 3 years ago

Remove svn keywords

File size: 7.2 KB
Line 
1MODULE readwrite
2  !
3  USE types
4  !
5  IMPLICIT NONE
6  !
7CONTAINS
8  !       
9  !*****************************************************
10  !   function Read_Coordinates(name,Grid)
11  !*****************************************************
12  INTEGER FUNCTION read_coordinates(name,Grid)
13    !
14    USE io_netcdf
15    !         
16    CHARACTER(*) name
17    TYPE(coordinates) :: Grid
18    !     
19    CALL Read_Ncdf_var('glamt',name,Grid%glamt)
20    CALL Read_Ncdf_var('glamu',name,Grid%glamu)
21    CALL Read_Ncdf_var('glamv',name,Grid%glamv)
22    CALL Read_Ncdf_var('glamf',name,Grid%glamf)
23    CALL Read_Ncdf_var('gphit',name,Grid%gphit)
24    CALL Read_Ncdf_var('gphiu',name,Grid%gphiu)
25    CALL Read_Ncdf_var('gphiv',name,Grid%gphiv)
26    CALL Read_Ncdf_var('gphif',name,Grid%gphif)
27    CALL Read_Ncdf_var('e1t',name,Grid%e1t)
28    CALL Read_Ncdf_var('e1u',name,Grid%e1u)
29    CALL Read_Ncdf_var('e1v',name,Grid%e1v)
30    CALL Read_Ncdf_var('e1f',name,Grid%e1f)
31    CALL Read_Ncdf_var('e2t',name,Grid%e2t)
32    CALL Read_Ncdf_var('e2u',name,Grid%e2u)
33    CALL Read_Ncdf_var('e2v',name,Grid%e2v)
34    CALL Read_Ncdf_var('e2f',name,Grid%e2f)
35    CALL Read_Ncdf_var('nav_lon',name,Grid%nav_lon)
36    CALL Read_Ncdf_var('nav_lat',name,Grid%nav_lat)       
37    !           
38    WRITE(*,*) ' '
39    WRITE(*,*) '*** Reading coordinates file: ',name
40    WRITE(*,*) ' '
41    !     
42    read_coordinates = 1
43    !     
44  END FUNCTION read_coordinates
45  !
46  !
47  !
48  !*****************************************************
49  !   function Write_Coordinates(name,Grid)
50  !*****************************************************
51  INTEGER FUNCTION write_coordinates(name,Grid,kxfine,kyfine)
52    !
53    USE io_netcdf
54   !
55    CHARACTER(*) name
56    TYPE(coordinates) :: Grid
57    INTEGER :: status,ncid,z
58    REAL*8,DIMENSION(:),POINTER :: tabtemp
59    INTEGER,DIMENSION(:),POINTER :: tabint
60    CHARACTER(len=20),DIMENSION(4) :: dimnames
61   INTEGER :: kxfine, kyfine
62    !
63    status = nf90_create(name,NF90_WRITE,ncid)
64    status = nf90_close(ncid)
65    !           
66   CALL Write_Ncdf_dim('x',name,nxfine)
67    CALL Write_Ncdf_dim('y',name,nyfine)
68    IF(.NOT. ln_iom_activated) CALL Write_Ncdf_dim('z',name,1)
69    CALL Write_Ncdf_dim('time',name,0)
70    !     
71    dimnames(1)='x'
72    dimnames(2)='y'
73    CALL Write_Ncdf_var('nav_lon',dimnames(1:2),name,Grid%nav_lon,'float')     
74    CALL Write_Ncdf_var('nav_lat',dimnames(1:2),name,Grid%nav_lat,'float')
75    !
76    IF(.NOT. ln_iom_activated) THEN
77       ! copy nav_lev variable -> IOIPSL
78       CALL Read_Ncdf_dim('z',cn_parent_coordinate_file,z)
79       ALLOCATE(tabtemp(z))
80       CALL Read_Ncdf_var('nav_lev',TRIM(cn_parent_coordinate_file),tabtemp)
81       CALL Write_Ncdf_var('nav_lev','z',name,tabtemp,'float')           
82       DEALLOCATE(tabtemp)
83    ENDIF
84    !
85    CALL Read_Ncdf_var('time',TRIM(cn_parent_coordinate_file),tabtemp)
86    CALL Write_Ncdf_var('time','time',name,tabtemp,'float')           
87    DEALLOCATE(tabtemp)     
88    CALL Read_Ncdf_var('time_steps',TRIM(cn_parent_coordinate_file),tabint)
89    CALL Write_Ncdf_var('time_steps','time',name,tabint) 
90    !     
91    dimnames(1)='x'
92    dimnames(2)='y'
93    IF(ln_iom_activated) THEN
94       dimnames(3)='time'
95    ELSE
96       dimnames(3)='z'
97       dimnames(4)='time'
98    ENDIF
99
100    CALL Write_Ncdf_var('glamt',dimnames,name,Grid%glamt,3,'double')
101    CALL Write_Ncdf_var('glamu',dimnames,name,Grid%glamu,3,'double')
102    CALL Write_Ncdf_var('glamv',dimnames,name,Grid%glamv,3,'double')
103    CALL Write_Ncdf_var('glamf',dimnames,name,Grid%glamf,3,'double')
104    CALL Write_Ncdf_var('gphit',dimnames,name,Grid%gphit,3,'double')
105    CALL Write_Ncdf_var('gphiu',dimnames,name,Grid%gphiu,3,'double')
106    CALL Write_Ncdf_var('gphiv',dimnames,name,Grid%gphiv,3,'double')
107    CALL Write_Ncdf_var('gphif',dimnames,name,Grid%gphif,3,'double')     
108    CALL Write_Ncdf_var('e1t',dimnames,name,Grid%e1t,3,'double')     
109    CALL Write_Ncdf_var('e1u',dimnames,name,Grid%e1u,3,'double')     
110    CALL Write_Ncdf_var('e1v',dimnames,name,Grid%e1v,3,'double')     
111    CALL Write_Ncdf_var('e1f',dimnames,name,Grid%e1f,3,'double')
112    CALL Write_Ncdf_var('e2t',dimnames,name,Grid%e2t,3,'double')
113    CALL Write_Ncdf_var('e2u',dimnames,name,Grid%e2u,3,'double')
114    CALL Write_Ncdf_var('e2v',dimnames,name,Grid%e2v,3,'double')
115    CALL Write_Ncdf_var('e2f',dimnames,name,Grid%e2f,3,'double')
116    !     
117    CALL Copy_Ncdf_att('nav_lon',TRIM(cn_parent_coordinate_file),name,&
118         MINVAL(Grid%nav_lon),MAXVAL(Grid%nav_lon))
119    CALL Copy_Ncdf_att('nav_lat',TRIM(cn_parent_coordinate_file),name,&
120         MINVAL(Grid%nav_lat),MAXVAL(Grid%nav_lat))
121    CALL Copy_Ncdf_att('nav_lev',TRIM(cn_parent_coordinate_file),name)
122    CALL Copy_Ncdf_att('time',TRIM(cn_parent_coordinate_file),name)
123    CALL Copy_Ncdf_att('time_steps',TRIM(cn_parent_coordinate_file),name)
124    CALL Copy_Ncdf_att('glamt',TRIM(cn_parent_coordinate_file),name)
125    CALL Copy_Ncdf_att('glamu',TRIM(cn_parent_coordinate_file),name)
126    CALL Copy_Ncdf_att('glamv',TRIM(cn_parent_coordinate_file),name)
127    CALL Copy_Ncdf_att('glamf',TRIM(cn_parent_coordinate_file),name)
128    CALL Copy_Ncdf_att('gphit',TRIM(cn_parent_coordinate_file),name)
129    CALL Copy_Ncdf_att('gphiu',TRIM(cn_parent_coordinate_file),name)
130    CALL Copy_Ncdf_att('gphiv',TRIM(cn_parent_coordinate_file),name)
131    CALL Copy_Ncdf_att('gphif',TRIM(cn_parent_coordinate_file),name)
132    CALL Copy_Ncdf_att('e1t',TRIM(cn_parent_coordinate_file),name)
133    CALL Copy_Ncdf_att('e1u',TRIM(cn_parent_coordinate_file),name)
134    CALL Copy_Ncdf_att('e1v',TRIM(cn_parent_coordinate_file),name)
135    CALL Copy_Ncdf_att('e1f',TRIM(cn_parent_coordinate_file),name)
136    CALL Copy_Ncdf_att('e2t',TRIM(cn_parent_coordinate_file),name)
137    CALL Copy_Ncdf_att('e2u',TRIM(cn_parent_coordinate_file),name)
138    CALL Copy_Ncdf_att('e2v',TRIM(cn_parent_coordinate_file),name)
139    CALL Copy_Ncdf_att('e2f',TRIM(cn_parent_coordinate_file),name)           
140    !
141    WRITE(*,*) ' '
142    WRITE(*,*) 'Writing coordinates file: ',name
143    IF(.NOT. ln_iom_activated) WRITE(*,*) 'IOISPL format'
144    IF(ln_iom_activated) WRITE(*,*) 'IOM format'     
145    WRITE(*,*) ' '
146    !
147    write_coordinates = 1
148    !     
149  END FUNCTION write_coordinates
150  !
151  !
152  !
153  !*****************************************************
154  !   function set_child_name(Parentname,Childname)
155  !*****************************************************
156  SUBROUTINE set_child_name(Parentname,Childname)
157    !
158    CHARACTER(*),INTENT(in) :: Parentname
159    CHARACTER(*),INTENT(out) :: Childname
160    CHARACTER(2) :: prefix
161    INTEGER :: pos
162    !   
163    pos  = INDEX(TRIM(Parentname),'/',back=.TRUE.)
164    !
165    prefix=Parentname(pos+1:pos+2)
166    IF (prefix == '1_') THEN
167       Childname = '2_'//Parentname(pos+3:LEN(Parentname)) 
168    ELSEIF (prefix == '2_') THEN
169       Childname = '3_'//Parentname(pos+3:LEN(Parentname)) 
170    ELSEIF (prefix == '3_') THEN
171       Childname = '4_'//Parentname(pos+3:LEN(Parentname)) 
172    ELSEIF (prefix == '4_') THEN
173       Childname = '5_'//Parentname(pos+3:LEN(Parentname)) 
174    ELSE
175       Childname = '1_'//Parentname(pos+1:LEN(Parentname)) 
176    ENDIF
177    !   
178  END SUBROUTINE set_child_name
179  !
180!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!             
181!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
182END MODULE readwrite
Note: See TracBrowser for help on using the repository browser.