source: CPL/oasis3-mct/branches/OASIS3-MCT_5.0_branch/examples/regrid_environment/create_grids_masks_with_F90/create_aux_files.F90 @ 6331

Last change on this file since 6331 was 6331, checked in by aclsce, 17 months ago

Moved oasis-mct_5.0 in oasis3-mct/branches directory.

File size: 5.5 KB
Line 
1!------------------------------------------------------------------------
2! Copyright 2010, CERFACS, Toulouse, France.
3! All rights reserved. Use is subject to OASIS3 license terms.
4!=============================================================================
5!
6!
7PROGRAM create_aux_files
8  !
9  ! Use for netCDF library
10  USE netcdf
11  !
12  IMPLICIT NONE
13  !
14  INTEGER, PARAMETER :: wp = SELECTED_REAL_KIND(12,307) ! double
15  !
16  CHARACTER(len=30)   :: data_filename_g1
17  CHARACTER(len=30)   :: data_filename_g2
18  !
19  CHARACTER(len=128) :: comp_out                 ! name of the output log file
20  CHARACTER(len=2)   :: chout
21  CHARACTER(len=4)   :: src_grd_ini, src_grd_end ! Source grid names
22  CHARACTER(len=4)   :: tgt_grd_ini, tgt_grd_end ! Source grid names
23  !
24  ! Global grid parameters :
25  INTEGER :: nlon1, nlat1     ! dimensions in the 2 directions of space
26  INTEGER :: nlon2, nlat2     ! dimensions in the 2 directions of space
27  INTEGER :: ntot             ! total dimension
28  INTEGER :: nc               ! number of corners
29  !
30  DOUBLE PRECISION, DIMENSION(:,:), POINTER    :: ggrid1_lon,ggrid1_lat ! lon, lat of the points
31  DOUBLE PRECISION, DIMENSION(:,:,:), POINTER  :: ggrid1_clo,ggrid1_cla ! lon, lat of the corners
32  INTEGER, DIMENSION(:,:), POINTER             :: g1_mask !
33  DOUBLE PRECISION, DIMENSION(:,:), POINTER    :: ggrid2_lon,ggrid2_lat ! lon, lat of the points
34  DOUBLE PRECISION, DIMENSION(:,:,:), POINTER  :: ggrid2_clo,ggrid2_cla ! lon, lat of the corners
35  INTEGER, DIMENSION(:,:), POINTER             :: g2_mask !
36  !
37  INTEGER :: ierror
38  INTEGER :: i, j
39  !
40  INTEGER, PARAMETER    :: w_unit = 15
41  !
42  !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
43  !  GET THE NAME OF THE INITIAL GRIDS AND FINAL GRIDS
44  !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
45  CALL getarg(1,data_filename_g1)
46  PRINT *, 'Source grid file = ', data_filename_g1
47  CALL getarg(2,data_filename_g2)
48  PRINT *, 'Target grid file = ', data_filename_g2
49  CALL getarg(3,src_grd_ini)
50  PRINT *, 'Initial Source grid acronym = ', src_grd_ini
51  CALL getarg(4,tgt_grd_ini)
52  PRINT *, ' Initial Target grid acronym = ', tgt_grd_ini
53  CALL getarg(5,src_grd_end)
54  PRINT *, 'Final Source grid acronym = ', src_grd_end
55  CALL getarg(6,tgt_grd_end)
56  PRINT *, ' Final Target grid acronym = ', tgt_grd_end
57
58  comp_out='create_aux_files.out'
59  OPEN(w_unit,file=TRIM(comp_out),form='formatted')
60  !
61  !
62  !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
63  !  READ GRIDS OF THE TWO MODELS
64  !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
65  !
66  ! Reading dimensions of the first global grid
67  CALL read_dimgrid(nlon1,nlat1,data_filename_g1,w_unit,src_grd_ini)
68  nc=4
69  !
70  ! Allocation
71  ALLOCATE(ggrid1_lon(nlon1,nlat1), STAT=ierror )
72  IF ( ierror /= 0 ) WRITE(w_unit,*) 'Error allocating globalgrid_lon'
73  ALLOCATE(ggrid1_lat(nlon1,nlat1), STAT=ierror )
74  IF ( ierror /= 0 ) WRITE(w_unit,*) 'Error allocating globalgrid_lat'
75  ALLOCATE(ggrid1_clo(nlon1,nlat1,nc), STAT=ierror )
76  IF ( ierror /= 0 ) WRITE(w_unit,*) 'Error allocating globalgrid_clo'
77  ALLOCATE(ggrid1_cla(nlon1,nlat1,nc), STAT=ierror )
78  IF ( ierror /= 0 ) WRITE(w_unit,*) 'Error allocating globalgrid_cla'
79  ALLOCATE(g1_mask(nlon1,nlat1), STAT=ierror )
80  IF ( ierror /= 0 ) WRITE(w_unit,*) 'Error allocating indice_mask'
81  !
82  ! Reading of the longitudes, latitudes, longitude and latitudes of the corners, mask of the global grid
83  CALL read_grid_mask(nlon1,nlat1,nc, data_filename_g1, w_unit, src_grd_ini,  &
84                      ggrid1_lon,ggrid1_lat, &
85                      ggrid1_clo,ggrid1_cla, &
86                      g1_mask)
87
88  ! Mask inversion to follow (historical) OASIS3 convention (0=not masked;1=masked)
89  WHERE(g1_mask == 1) 
90      g1_mask=0
91  ELSEWHERE
92      g1_mask=1
93  END WHERE
94  !
95  ! Reading dimensions of the second global grid
96  CALL read_dimgrid(nlon2,nlat2,data_filename_g2,w_unit,tgt_grd_ini)
97  nc=4
98  !
99  ! Allocation
100  ALLOCATE(ggrid2_lon(nlon2,nlat2), STAT=ierror )
101  IF ( ierror /= 0 ) WRITE(w_unit,*) 'Error allocating globalgrid_lon'
102  ALLOCATE(ggrid2_lat(nlon2,nlat2), STAT=ierror )
103  IF ( ierror /= 0 ) WRITE(w_unit,*) 'Error allocating globalgrid_lat'
104  ALLOCATE(ggrid2_clo(nlon2,nlat2,nc), STAT=ierror )
105  IF ( ierror /= 0 ) WRITE(w_unit,*) 'Error allocating globalgrid_clo'
106  ALLOCATE(ggrid2_cla(nlon2,nlat2,nc), STAT=ierror )
107  IF ( ierror /= 0 ) WRITE(w_unit,*) 'Error allocating globalgrid_cla'
108  ALLOCATE(g2_mask(nlon2,nlat2), STAT=ierror )
109  IF ( ierror /= 0 ) WRITE(w_unit,*) 'Error allocating indice_mask'
110  !
111  ! Reading of the longitudes, latitudes, longitude and latitudes of the corners, mask of the global grid
112  CALL read_grid_mask(nlon2,nlat2,nc, data_filename_g2, w_unit, tgt_grd_ini,  &
113                      ggrid2_lon,ggrid2_lat, &
114                      ggrid2_clo,ggrid2_cla, &
115                      g2_mask)
116
117  ! Mask inversion to follow (historical) OASIS3 convention (0=not masked;1=masked)
118  WHERE(g2_mask == 1) 
119      g2_mask=0
120  ELSEWHERE
121      g2_mask=1
122  END WHERE
123  !
124  !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
125  !  WRITE grids.nc and masks.nc with both source and target grids
126  !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
127  !
128  CALL write_grids_masks(nlon1,nlat1,nlon2,nlat2,nc, &
129                         src_grd_end, tgt_grd_end, w_unit, &
130                         ggrid1_lon,ggrid1_lat,ggrid1_clo,ggrid1_cla,g1_mask, &
131                         ggrid2_lon,ggrid2_lat,ggrid2_clo,ggrid2_cla,g2_mask)
132  !
133  CLOSE (w_unit)
134  !
135END PROGRAM create_aux_files
136
Note: See TracBrowser for help on using the repository browser.