|
◆ grid_transform_init()
subroutine grid_transform_init |
( |
type(grid_transform), intent(out) |
this, |
|
|
type(transform_def), intent(in) |
trans, |
|
|
type(griddim_def), intent(inout) |
in, |
|
|
type(griddim_def), intent(inout) |
out, |
|
|
real, dimension(:,:), intent(in), optional |
maskgrid, |
|
|
real, dimension(:), intent(in), optional |
maskbounds, |
|
|
character(len=*), intent(in), optional |
categoryappend |
|
) |
| |
Constructor for a grid_transform object, defining a particular grid-to-grid transformation.
It defines an object describing a transformation from one rectangular grid to another; the abstract type of transformation is described in the transformation object trans (type transform_def) which must have been properly initialised. The additional information required here is the description of the input grid in (type griddim_def), the description of the output grid out (type griddim_def as well). The description of the output grid must be initialized for interpolating type transformations ('inter' and 'boxinter'), while it is generated by this constructor and returned in output for 'zoom', 'boxregrid', 'maskgen' and 'polyinter' transformations.
The generated grid_transform object is specific to the input and output grids involved. The function c_e can be used in order to check whether the object has been successfully initialised, if the result is .FALSE., it should not be used further on.
- Parametri
-
[out] | this | grid_transformation object |
[in] | trans | transformation object |
[in,out] | in | griddim object to transform |
[in,out] | out | griddim object defining target grid (input or output depending on type of transformation) |
[in] | maskgrid | 2D field to be used for defining valid points, it must have the same shape as the field to be interpolated (for transformation type 'metamorphosis:maskvalid') |
[in] | maskbounds | array of boundary values for defining a subset of valid points where the values of maskgrid are within the first and last value of maskbounds (for transformation type 'metamorphosis:maskvalid/settoinvalid' and others) |
[in] | categoryappend | append this suffix to log4fortran namespace category |
Definizione alla linea 1416 del file grid_transform_class.F90.
1416 CALL get_val(out, dx=this%trans%area_info%boxdx) 1417 IF (.NOT. c_e(this%trans%area_info%boxdy)) & 1418 CALL get_val(out, dx=this%trans%area_info%boxdy) 1420 this%trans%area_info%boxdx = this%trans%area_info%boxdx*0.5d0 1421 this%trans%area_info%boxdy = this%trans%area_info%boxdy*0.5d0 1423 ALLOCATE(this%inter_index_x(this%innx,this%inny), & 1424 this%inter_index_y(this%innx,this%inny)) 1429 CALL find_index(out, 'near', & 1430 this%outnx, this%outny, xmin, xmax, ymin, ymax, & 1431 in%dim%lon, in%dim%lat, .false., & 1432 this%inter_index_x, this%inter_index_y) 1436 ELSE IF (this%trans%trans_type == 'stencilinter') THEN 1438 CALL outgrid_setup() 1440 CALL get_val(in, nx=this%innx, ny=this%inny, & 1441 xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax) 1442 CALL get_val(out, nx=this%outnx, ny=this%outny) 1444 ALLOCATE (this%inter_index_x(this%outnx,this%outny), & 1445 this%inter_index_y(this%outnx,this%outny)) 1447 CALL find_index(in, 'near', & 1448 this%innx, this%inny, xmin, xmax, ymin, ymax, & 1449 out%dim%lon, out%dim%lat, this%trans%extrap, & 1450 this%inter_index_x, this%inter_index_y) 1453 nr = int(this%trans%area_info%radius) 1456 r2 = this%trans%area_info%radius**2 1457 ALLOCATE(this%stencil(n,n)) 1458 this%stencil(:,:) = .true. 1461 IF ((ix-nm)**2+(iy-nm)**2 > r2) this%stencil(ix,iy) = .false. 1468 xnmax = this%innx - nr 1470 ynmax = this%inny - nr 1471 DO iy = 1, this%outny 1472 DO ix = 1, this%outnx 1473 IF (this%inter_index_x(ix,iy) < xnmin .OR. & 1474 this%inter_index_x(ix,iy) > xnmax .OR. & 1475 this%inter_index_y(ix,iy) < ynmin .OR. & 1476 this%inter_index_y(ix,iy) > ynmax) THEN 1477 this%inter_index_x(ix,iy) = imiss 1478 this%inter_index_y(ix,iy) = imiss 1484 CALL l4f_category_log(this%category, l4f_debug, & 1485 'stencilinter: stencil size '// t2c(n*n)) 1486 CALL l4f_category_log(this%category, l4f_debug, & 1487 'stencilinter: stencil points '// t2c(count(this%stencil))) 1492 ELSE IF (this%trans%trans_type == 'maskgen' .OR. & 1493 this%trans%trans_type == 'polyinter') THEN 1495 IF (this%trans%trans_type == 'polyinter') THEN 1500 CALL get_val(in, nx=this%innx, ny=this%inny) 1501 this%outnx = this%innx 1502 this%outny = this%inny 1505 ALLOCATE(this%inter_index_x(this%innx,this%inny), & 1506 this%inter_index_y(this%innx,this%inny)) 1507 this%inter_index_x(:,:) = imiss 1508 this%inter_index_y(:,:) = 1 1517 inside_x: DO i = 1, this%innx 1518 point = georef_coord_new(x=in%dim%lon(i,j), y=in%dim%lat(i,j)) 1520 DO n = nprev, this%trans%poly%arraysize 1521 IF (inside(point, this%trans%poly%array(n))) THEN 1522 this%inter_index_x(i,j) = n 1527 DO n = nprev-1, 1, -1 1528 IF (inside(point, this%trans%poly%array(n))) THEN 1529 this%inter_index_x(i,j) = n 1542 ELSE IF (this%trans%trans_type == 'metamorphosis') THEN 1545 CALL get_val(in, nx=this%innx, ny=this%inny) 1546 this%outnx = this%innx 1547 this%outny = this%inny 1549 IF (this%trans%sub_type == 'maskvalid' .OR. this%trans%sub_type == 'maskinvalid') THEN 1551 IF (.NOT. PRESENT(maskgrid)) THEN 1552 CALL l4f_category_log(this%category,l4f_error, & 1553 'grid_transform_init maskgrid argument missing for metamorphosis:'// & 1554 trim(this%trans%sub_type)// ' transformation') 1559 IF (this%innx /= SIZE(maskgrid,1) .OR. this%inny /= SIZE(maskgrid,2)) THEN 1560 CALL l4f_category_log(this%category,l4f_error, & 1561 'grid_transform_init mask non conformal with input field') 1562 CALL l4f_category_log(this%category,l4f_error, & 1563 'mask: '// t2c( SIZE(maskgrid,1))// 'x'// t2c( SIZE(maskgrid,2))// & 1564 ' input field:'// t2c(this%innx)// 'x'// t2c(this%inny)) 1569 ALLOCATE(this%point_mask(this%innx,this%inny)) 1571 IF (this%trans%sub_type == 'maskvalid') THEN 1574 IF (.NOT. PRESENT(maskbounds)) THEN 1575 this%point_mask(:,:) = c_e(maskgrid(:,:)) 1576 ELSE IF ( SIZE(maskbounds) < 2) THEN 1577 this%point_mask(:,:) = c_e(maskgrid(:,:)) 1579 this%point_mask(:,:) = c_e(maskgrid(:,:)) .AND. & 1580 maskgrid(:,:) > maskbounds(1) .AND. & 1581 maskgrid(:,:) <= maskbounds( SIZE(maskbounds)) 1584 this%point_mask(:,:) = .NOT. c_e(maskgrid(:,:)) 1589 ELSE IF (this%trans%sub_type == 'setinvalidto') THEN 1591 IF (.NOT. PRESENT(maskbounds)) THEN 1592 CALL l4f_category_log(this%category,l4f_error, & 1593 'grid_transform_init maskbounds missing for metamorphosis:'// & 1594 trim(this%trans%sub_type)// ' transformation') 1596 ELSE IF ( SIZE(maskbounds) < 1) THEN 1597 CALL l4f_category_log(this%category,l4f_error, & 1598 'grid_transform_init maskbounds empty for metamorphosis:'// & 1599 trim(this%trans%sub_type)// ' transformation') 1602 this%val1 = maskbounds(1) 1604 CALL l4f_category_log(this%category, l4f_debug, & 1605 "grid_transform_init setting invalid data to "// t2c(this%val1)) 1611 ELSE IF (this%trans%sub_type == 'settoinvalid') THEN 1613 IF (.NOT. PRESENT(maskbounds)) THEN 1614 CALL l4f_category_log(this%category,l4f_error, & 1615 'grid_transform_init maskbounds missing for metamorphosis:'// & 1616 trim(this%trans%sub_type)// ' transformation') 1619 ELSE IF ( SIZE(maskbounds) < 2) THEN 1620 CALL l4f_category_log(this%category,l4f_error, & 1621 'grid_transform_init maskbounds must have at least 2 elements for metamorphosis:'// & 1622 trim(this%trans%sub_type)// ' transformation') 1626 this%val1 = maskbounds(1) 1627 this%val2 = maskbounds( SIZE(maskbounds)) 1629 CALL l4f_category_log(this%category, l4f_debug, & 1630 "grid_transform_init setting to invalid interval ]"// t2c(this%val1)// ','// & 1631 t2c(this%val2)// ']') 1645 SUBROUTINE outgrid_setup() 1648 CALL griddim_setsteps(out) 1650 CALL get_val(in, proj=proj_in, component_flag=cf_i) 1651 CALL get_val(out, proj=proj_out, component_flag=cf_o) 1652 IF (proj_in == proj_out) THEN 1655 CALL set_val(out, component_flag=cf_i) 1660 CALL l4f_category_log(this%category,l4f_warn, & 1661 'trying to interpolate a grid with component flag 1 to a grid on a different projection') 1662 CALL l4f_category_log(this%category,l4f_warn, & 1663 'vector fields will probably be wrong') 1665 CALL set_val(out, component_flag=cf_i) 1669 CALL griddim_set_central_lon(in, griddim_central_lon(out)) 1671 END SUBROUTINE outgrid_setup 1673 END SUBROUTINE grid_transform_init 1718 SUBROUTINE grid_transform_grid_vol7d_init(this, trans, in, v7d_out, & 1719 maskgrid, maskbounds, categoryappend) 1720 TYPE(grid_transform), INTENT(out) :: this 1721 TYPE(transform_def), INTENT(in) :: trans 1722 TYPE(griddim_def), INTENT(inout) :: in 1723 TYPE(vol7d), INTENT(inout) :: v7d_out 1724 REAL, INTENT(in), OPTIONAL :: maskgrid(:,:) 1725 REAL, INTENT(in), OPTIONAL :: maskbounds(:) 1726 CHARACTER(len=*), INTENT(in), OPTIONAL :: categoryappend 1728 INTEGER :: ix, iy, n, nm, nr, nprev, nmaskarea, xnmin, xnmax, ynmin, ynmax, & 1730 DOUBLE PRECISION :: xmin, xmax, ymin, ymax, r2 1731 DOUBLE PRECISION, ALLOCATABLE :: lon(:), lat(:) 1732 REAL, ALLOCATABLE :: lmaskbounds(:) 1733 TYPE(georef_coord) :: point 1736 CALL grid_transform_init_common(this, trans, categoryappend) 1738 CALL l4f_category_log(this%category, l4f_debug, "grid_transform vg6d-v7d") 1742 CALL get_val(trans, time_definition=time_definition) 1743 IF (.NOT. c_e(time_definition)) THEN 1747 IF (this%trans%trans_type == 'inter') THEN 1749 IF (this%trans%sub_type == 'near' .OR. this%trans%sub_type == 'bilin' & 1750 .OR. this%trans%sub_type == 'shapiro_near') THEN 1752 CALL get_val(in, nx=this%innx, ny=this%inny) 1753 this%outnx = SIZE(v7d_out%ana) 1756 ALLOCATE (this%inter_index_x(this%outnx,this%outny),& 1757 this%inter_index_y(this%outnx,this%outny)) 1758 ALLOCATE(lon(this%outnx),lat(this%outnx)) 1760 CALL get_val(in, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax) 1761 CALL getval(v7d_out%ana(:)%coord,lon=lon,lat=lat) 1763 CALL find_index(in, this%trans%sub_type,& 1764 this%innx, this%inny, xmin, xmax, ymin, ymax, & 1765 lon, lat, this%trans%extrap, & 1766 this%inter_index_x(:,1), this%inter_index_y(:,1)) 1768 IF ( this%trans%sub_type == 'bilin' ) THEN 1769 ALLOCATE(this%inter_x(this%innx,this%inny),this%inter_y(this%innx,this%inny)) 1770 ALLOCATE(this%inter_xp(this%outnx,this%outny),this%inter_yp(this%outnx,this%outny)) 1772 CALL griddim_gen_coord(in, this%inter_x, this%inter_y) 1773 CALL proj(in, reshape(lon,(/ SIZE(lon),1/)),reshape(lat,(/ SIZE(lat),1/)),& 1774 this%inter_xp,this%inter_yp) 1783 ELSE IF (this%trans%trans_type == 'polyinter') THEN 1785 CALL get_val(in, nx=this%innx, ny=this%inny) 1787 ALLOCATE(this%inter_index_x(this%innx,this%inny), & 1788 this%inter_index_y(this%innx,this%inny)) 1789 this%inter_index_x(:,:) = imiss 1790 this%inter_index_y(:,:) = 1 1798 DO iy = 1, this%inny 1799 inside_x: DO ix = 1, this%innx 1800 point = georef_coord_new(x=in%dim%lon(ix,iy), y=in%dim%lat(ix,iy)) 1802 DO n = nprev, this%trans%poly%arraysize 1803 IF (inside(point, this%trans%poly%array(n))) THEN 1804 this%inter_index_x(ix,iy) = n 1809 DO n = nprev-1, 1, -1 1810 IF (inside(point, this%trans%poly%array(n))) THEN 1811 this%inter_index_x(ix,iy) = n 1822 this%outnx = this%trans%poly%arraysize 1825 CALL init(v7d_out, time_definition=time_definition) 1826 CALL vol7d_alloc(v7d_out, nana=this%outnx) 1830 DO n = 1, this%trans%poly%arraysize 1831 CALL getval(this%trans%poly%array(n), x=lon, y=lat) 1832 CALL init(v7d_out%ana(n), lon=stat_average(lon), lat=stat_average(lat)) 1837 DO n = 1, this%trans%poly%arraysize 1838 CALL l4f_category_log(this%category, l4f_debug, & 1839 'Polygon: '// t2c(n)// ' grid points: '// & 1840 t2c(count(this%inter_index_x(:,:) == n))) 1846 ELSE IF (this%trans%trans_type == 'stencilinter') THEN 1849 CALL get_val(in, nx=this%innx, ny=this%inny) 1850 this%outnx = SIZE(v7d_out%ana) 1853 ALLOCATE (this%inter_index_x(this%outnx,this%outny),& 1854 this%inter_index_y(this%outnx,this%outny)) 1855 ALLOCATE(lon(this%outnx),lat(this%outnx)) 1857 CALL get_val(in, xmin=xmin, xmax=xmax, ymin=ymin, ymax=ymax) 1858 CALL getval(v7d_out%ana(:)%coord,lon=lon,lat=lat) 1860 CALL find_index(in, 'near',& 1861 this%innx, this%inny, xmin, xmax, ymin, ymax, & 1862 lon, lat, this%trans%extrap, & 1863 this%inter_index_x(:,1), this%inter_index_y(:,1)) 1866 nr = int(this%trans%area_info%radius) 1869 r2 = this%trans%area_info%radius**2 1870 ALLOCATE(this%stencil(n,n)) 1871 this%stencil(:,:) = .true. 1874 IF ((ix-nm)**2+(iy-nm)**2 > r2) this%stencil(ix,iy) = .false. 1881 xnmax = this%innx - nr 1883 ynmax = this%inny - nr 1884 DO iy = 1, this%outny 1885 DO ix = 1, this%outnx Functions that return a trimmed CHARACTER representation of the input variable.
Distruttori per le 2 classi.
Restituiscono il valore dell'oggetto nella forma desiderata.
Costruttori per le classi datetime e timedelta.
|