28 u gridman_unit,gridman_tol
29 USE gridman_lib,ONLY:gridman_grid_read,gridman_grid_write,
32 INTRINSIC len_trim,get_command_argument,adjustl,trim
36 SUBROUTINE cutgrid_read_contour(CONTOUR_IN,UNIT2METER,XP,YP,NP)
38 CHARACTER(LEN=256),
INTENT(IN) :: contour_in
39 REAL(GRIDMAN_DP),
INTENT(IN) :: unit2meter
40 INTEGER(GRIDMAN_SP),
INTENT(OUT) :: np
41 REAL(GRIDMAN_DP),
ALLOCATABLE :: xp(:),yp(:)
42 END SUBROUTINE cutgrid_read_contour
44 SUBROUTINE cutrgrid_mergeindex(GRID,IEIND)
47 INTEGER,
INTENT(IN) :: ieind
48 END SUBROUTINE cutrgrid_mergeindex
53 CHARACTER(LEN=256) :: description,
54 c grid_in,contour_in,grid_out
55 LOGICAL :: lexclude,dbgmod,lcheck
56 REAL(GRIDMAN_DP) :: unit2meter,tol
59 INTEGER(GRIDMAN_SP) :: np
62 REAL(GRIDMAN_DP),
ALLOCATABLE :: xp(:),yp(:)
63 CHARACTER(LEN=8) :: ftmp
65 CALL get_command_argument(1,ftmp)
66 IF(len_trim(ftmp).GT.0)
THEN
67 IF(adjustl(trim(ftmp)).EQ.
'help')
THEN
79 WRITE(gridman_unit,*)
"CUTGRID: reading file ",grid_in(1:lt)
80 CALL gridman_grid_read(grid0,grid_in,ierr)
81 IF(ierr.GT.0)
CALL cutgrid_error(
"")
83 CALL cutgrid_error(
"GRID_IN is not defined")
87 CALL cutgrid_read_contour(contour_in,unit2meter,xp,yp,np)
90 WRITE(gridman_unit,*)
"CUTGRID: cut the grid"
92 IF(ierr.GT.0)
CALL cutgrid_error(
"")
93 lt=len_trim(description)
94 IF(lt.GT.0) grid1%DESCRIPTION=description
98 f grid1%NEDGEINDEX.GT.grid0%NEDGEINDEX)
THEN
99 WRITE(gridman_unit,*)
"CUTGRID: merging edge indexes"
100 CALL cutrgrid_mergeindex(grid1,ieind)
104 lt=len_trim(grid_out)
106 WRITE(gridman_unit,*)
"CUTGRID: writing file ",grid_out(1:lt)
107 CALL gridman_grid_write(grid1,grid_out,ierr)
108 IF(ierr.NE.0)
CALL cutgrid_error(
"")
114 WRITE(gridman_unit,*)
"CUTGRID COMPLETED"
121 SUBROUTINE read_input
122 namelist /cutgrid/ description,grid_in,grid_out,contour_in,
123 n lexclude,ieind,dbgmod,lcheck,tol,unit2meter
138 READ(5,nml=cutgrid,iostat=io)
139 IF(io.NE.0)
CALL cutgrid_error(
"can not read namelist CUTGRID")
141 IF(tol.GT.0) gridman_tol=tol
143 END SUBROUTINE read_input
148 INTRINSIC index,len,trim
149 INTEGER,
PARAMETER :: file_length=1024
150 CHARACTER(LEN=FILE_LENGTH) :: path
151 CHARACTER(LEN=128) :: str
153 CALL get_command_argument(0,path)
154 i=index(path,
'/',.true.)
155 IF(i.GT.len(path))
THEN
161 IF(
gridman_dbg)
WRITE(gridman_unit,*)
" PATH:",trim(path)
163 OPEN(unit=3,file=trim(path)//
'cutgrid.parameters.description',
164 o status=
'OLD',iostat=io)
168 READ(3,
'(A)',iostat=io,end=200) str
174 100
WRITE(gridman_unit,*)
175 w
"Could not find cutgrid.parameters.description",
177 WRITE(gridman_unit,*)
178 w
"Use 'which cutgrid' to invoke via the full path"
187 SUBROUTINE cutgrid_read_contour(CONTOUR_IN,UNIT2METER,XP,YP,NP)
191 INTRINSIC len_trim,abs,tiny
193 CHARACTER(LEN=256),
INTENT(IN) :: contour_in
194 REAL(GRIDMAN_DP),
INTENT(IN) :: unit2meter
195 INTEGER(GRIDMAN_SP),
INTENT(OUT) :: np
196 REAL(GRIDMAN_DP),
ALLOCATABLE :: xp(:),yp(:)
198 INTEGER(GRIDMAN_SP),
ALLOCATABLE :: n(:)
199 REAL(GRIDMAN_DP),
ALLOCATABLE :: x0(:),y0(:)
200 REAL(GRIDMAN_DP) :: dx,dy
201 INTEGER(GRIDMAN_SP) :: m,l,n0
202 INTEGER :: lt,st,ierr
204 lt=len_trim(contour_in)
206 WRITE(
gridman_unit,*)
"CUTGRID: reading file ",contour_in(1:lt)
207 CALL gridman_template_read(contour_in,m,n,l,x0,y0,ierr)
208 IF(ierr.GT.0)
CALL cutgrid_error(
"")
212 w
" more then one contour is defined in the file ",
217 dx=
gridman_tol*(abs(x0(1))+abs(x0(n0)))+10.*tiny(dx)
218 dy=
gridman_tol*(abs(y0(1))+abs(y0(n0)))+10.*tiny(dy)
219 IF( abs(x0(1)-x0(n0)).GT.dx.OR.
220 f abs(y0(1)-y0(n0)).GT.dy)
THEN
226 ALLOCATE(xp(np),yp(np),stat=st)
229 CALL cutgrid_error(
"Cannot allocate temporary arrays")
231 IF(unit2meter.GT.0.)
THEN
232 xp(1:n0)=x0(1:n0)*unit2meter
233 yp(1:n0)=y0(1:n0)*unit2meter
236 w
" UNIT2METER is not defined"
238 w
" I assume that the coordinates in file ",contour_in(1:lt)
240 xp(1:n0)=x0(1:n0)*1e-3
241 yp(1:n0)=y0(1:n0)*1e-3
248 w
"CUTGRID: point added to close the contour"
252 CALL cutgrid_error(
"CONTOUR_IN is not defined")
255 END SUBROUTINE cutgrid_read_contour
261 SUBROUTINE cutrgrid_mergeindex(GRID,IEIND)
267 INTEGER,
INTENT(IN) :: ieind
270 t indtmp(grid%NEDGEINDEX)
276 indseg=grid%EDGEINDEX(grid%NEDGEINDEX)
277 IF(ieind.LT.1.OR.ieind.GT.grid%NEDGEINDEX)
THEN
279 w ieind, grid%NEDGEINDEX
280 CALL cutgrid_error(
"IEIND is out of range")
282 ind0=grid%EDGEINDEX(ieind)
283 IF(ind0%NINDEX.NE.1)
THEN
285 CALL cutgrid_error(
"NINDEX of IEIND must be 1")
289 IF(ierr.NE.0)
CALL cutgrid_error(
"")
292 indtmp=grid%EDGEINDEX
293 DEALLOCATE(grid%EDGEINDEX)
294 ALLOCATE(grid%EDGEINDEX(grid%NEDGEINDEX+1))
295 grid%EDGEINDEX(1)=ind1
296 grid%EDGEINDEX(2:grid%NEDGEINDEX+1)=indtmp
297 grid%NEDGEINDEX=grid%NEDGEINDEX+1
299 END SUBROUTINE cutrgrid_mergeindex
304 SUBROUTINE cutgrid_error(STR)
307 CHARACTER(*),
INTENT(IN) :: str
313 stop
"ERROR in CUTGRID - see log output"
314 END SUBROUTINE cutgrid_error
integer, save, public gridman_unit
Index of the standard output unit.
real(gridman_dp), save, public gridman_tol
Tolerance parameter which is used to compare two real numbers.
integer, parameter, public gridman_dp
Kind parameter for real numbers.
Explicit interfaces to GRIDMAN subroutines and functions.
subroutine gridman_grid2d_cut(CUTGRID, GRID, XP, YP, NP, LEX, IERR)
Select part of a 2D grid cut by polygon.
Data-type which describes a grid as a set of edges, methods in grid.f.
subroutine gridman_grid_deallocate(GRID, IERR)
Deallocate grid object.
subroutine gridman_index_allocate(INDEX, NINDEX, NELEMENTS, IERR)
Allocate index object.
logical, save, public gridman_dbg
Switch for debugging mode.
Data-type which stores indices defined on the grid cells or edges.
subroutine print_description
Print manual.
subroutine gridman_index_merge(INDEX, INDEX1, INDEX2, IERR)
Merge INDEX2 into INDEX1.
Definition of data types, global constants and variables.
integer, parameter, public gridman_sp
Kind parameter for integer numbers.