libsim Versione 7.2.6
|
◆ grid_dim_display()
Display on the screen a brief content of the object.
Definizione alla linea 410 del file grid_dim_class.F90. 411! Copyright (C) 2010 ARPA-SIM <urpsim@smr.arpa.emr.it>
412! authors:
413! Davide Cesari <dcesari@arpa.emr.it>
414! Paolo Patruno <ppatruno@arpa.emr.it>
415
416! This program is free software; you can redistribute it and/or
417! modify it under the terms of the GNU General Public License as
418! published by the Free Software Foundation; either version 2 of
419! the License, or (at your option) any later version.
420
421! This program is distributed in the hope that it will be useful,
422! but WITHOUT ANY WARRANTY; without even the implied warranty of
423! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
424! GNU General Public License for more details.
425
426! You should have received a copy of the GNU General Public License
427! along with this program. If not, see <http://www.gnu.org/licenses/>.
428#include "config.h"
429!> Module for defining the extension and coordinates of a rectangular
430!! georeferenced grid.
431!!
432!!\ingroup volgrid6d
438IMPLICIT NONE
439
440!> Derived type describing the extension of a grid and the geographical
441!! coordinates of each point. It is not used alone but rather as a
442!! subtype of a \a griddim_def type.
444 INTEGER :: nx !< number of points along x dimension
445 INTEGER :: ny !< number of points along y dimension
446 DOUBLE PRECISION,POINTER :: lat(:,:) !< array of geographical latitudes
447 DOUBLE PRECISION,POINTER :: lon(:,:) !< array of geographical longitudes
449
450INTERFACE delete
451 MODULE PROCEDURE grid_dim_delete
452END INTERFACE
453
454INTERFACE copy
455 MODULE PROCEDURE grid_dim_copy
456END INTERFACE
457
458INTERFACE alloc
459 MODULE PROCEDURE grid_dim_alloc
460END INTERFACE
461
462INTERFACE dealloc
463 MODULE PROCEDURE grid_dim_dealloc
464END INTERFACE
465
466INTERFACE OPERATOR (==)
467 MODULE PROCEDURE grid_dim_eq
468END INTERFACE
469
470INTERFACE write_unit
471 MODULE PROCEDURE grid_dim_write_unit
472END INTERFACE
473
474INTERFACE read_unit
475 MODULE PROCEDURE grid_dim_read_unit
476END INTERFACE
477
478INTERFACE display
479 MODULE PROCEDURE grid_dim_display
480END INTERFACE
481
482PRIVATE grid_dim_delete, grid_dim_copy, grid_dim_alloc, grid_dim_dealloc, &
483 grid_dim_eq, grid_dim_read_unit, grid_dim_write_unit, grid_dim_display
484
485CONTAINS
486
487FUNCTION grid_dim_new(nx, ny) RESULT(this)
488INTEGER, INTENT(in), OPTIONAL :: nx, ny
489
490TYPE(grid_dim) :: this
491
492this%nx = optio_l(nx)
493this%ny = optio_l(ny)
494NULLIFY(this%lat, this%lon)
495
496END FUNCTION grid_dim_new
497
498
499SUBROUTINE grid_dim_delete(this)
500TYPE(grid_dim), INTENT(inout) :: this
501
502CALL dealloc(this)
503this%nx = imiss
504this%ny = imiss
505
506END SUBROUTINE grid_dim_delete
507
508
509SUBROUTINE grid_dim_alloc(this)
510TYPE(grid_dim),INTENT(inout) :: this
511
512IF (ASSOCIATED(this%lon) .AND. ASSOCIATED(this%lat)) THEN
513 IF (SIZE(this%lon, 1) == this%nx .AND. SIZE(this%lon, 2) == this%ny .AND. &
514 SIZE(this%lat, 1) == this%nx .AND. SIZE(this%lat, 2) == this%ny) RETURN
515ENDIF
516CALL dealloc(this)
518 ALLOCATE(this%lon(this%nx, this%ny), this%lat(this%nx, this%ny))
519ENDIF
520
521END SUBROUTINE grid_dim_alloc
522
523
524SUBROUTINE grid_dim_dealloc(this)
525TYPE(grid_dim),INTENT(inout) :: this
526
527IF (ASSOCIATED(this%lon)) DEALLOCATE(this%lon)
528IF (ASSOCIATED(this%lat)) DEALLOCATE(this%lat)
529
530END SUBROUTINE grid_dim_dealloc
531
532
533SUBROUTINE grid_dim_copy(this, that)
534TYPE(grid_dim),INTENT(in) :: this
535TYPE(grid_dim),INTENT(out) :: that
536
537that = grid_dim_new(this%nx, this%ny)
538
539IF (ASSOCIATED(this%lon) .AND. ASSOCIATED(this%lat))THEN
540 CALL alloc(that)
541
542#ifdef DEBUG
543 IF (SIZE(this%lon,1) /= this%nx .OR. SIZE(this%lon,2) /= this%ny) THEN
544 CALL raise_error('grid_dim_copy, dimensioni non valide: '// &
547 ENDIF
548 IF (SIZE(this%lat,1) /= this%nx .OR. SIZE(this%lat,2) /= this%ny) THEN
549 CALL raise_error('grid_dim_copy, dimensioni non valide: '// &
552 ENDIF
553#endif
554
555 that%lon(:,:) = this%lon(:,:)
556 that%lat(:,:) = this%lat(:,:)
557ENDIF
558
559END SUBROUTINE grid_dim_copy
560
561
562ELEMENTAL FUNCTION grid_dim_eq(this, that) RESULT(res)
563TYPE(grid_dim),INTENT(IN) :: this, that
564LOGICAL :: res
565
566res = this%nx == that%nx .and. &
567 this%ny == that%ny
568
569END FUNCTION grid_dim_eq
570
571
572!> This method reads from a Fortran file unit the contents of the
573!! object \a this. The record to be read must have been written with
574!! the ::write_unit method. The method works both on formatted and
575!! unformatted files.
576SUBROUTINE grid_dim_read_unit(this, unit)
577TYPE(grid_dim),INTENT(out) :: this !< object to be read
578INTEGER, INTENT(in) :: unit !< unit from which to read, it must be an opened Fortran file unit
579
580CHARACTER(len=40) :: form
581LOGICAL :: is_all
582
583INQUIRE(unit, form=form)
584IF (form == 'FORMATTED') THEN
585 READ(unit,*)this%nx,this%ny
586 READ(unit,*)is_all
587 IF (is_all) THEN
588 CALL alloc(this)
589 READ(unit,*)this%lon,this%lat
590 ELSE
591 READ(unit,*)
592 ENDIF
593ELSE
594 READ(unit)this%nx,this%ny
595 READ(unit)is_all
596 IF (is_all) THEN
597 CALL alloc(this)
598 READ(unit)this%lon,this%lat
599 ELSE
600 READ(unit)
601 ENDIF
602ENDIF
603
604END SUBROUTINE grid_dim_read_unit
605
606
607!> This method writes on a Fortran file unit the contents of the
608!! object \a this. The record can successively be read by the
609!! ::read_unit method. The method works both on formatted and
610!! unformatted files.
611SUBROUTINE grid_dim_write_unit(this, unit)
612TYPE(grid_dim),INTENT(in) :: this !< object to be written
613INTEGER, INTENT(in) :: unit !< unit where to write, it must be an opened Fortran file unit
614
615CHARACTER(len=40) :: form
616LOGICAL :: is_all
617
618INQUIRE(unit, form=form)
619IF (form == 'FORMATTED') THEN
620 WRITE(unit,*)this%nx,this%ny
621 is_all = (ASSOCIATED(this%lon) .AND. ASSOCIATED(this%lat))
622 WRITE(unit,*)is_all
623 IF (is_all) THEN
624 WRITE(unit,*)this%lon,this%lat
625 ELSE
626 WRITE(unit,*)
627 ENDIF
628ELSE
629 WRITE(unit)this%nx,this%ny
630 is_all = (ASSOCIATED(this%lon) .AND. ASSOCIATED(this%lat))
631 WRITE(unit)is_all
632 IF (is_all) THEN
633 WRITE(unit)this%lon,this%lat
634 ELSE
635 WRITE(unit)
636 ENDIF
637ENDIF
638
639END SUBROUTINE grid_dim_write_unit
640
641
642!> Display on the screen a brief content of the object.
643SUBROUTINE grid_dim_display(this)
644TYPE(grid_dim),INTENT(in) :: this !< object to display
645
646print*,'Number of points along x direction',this%nx
647print*,'Number of points along y direction',this%ny
648
649END SUBROUTINE grid_dim_display
650
Set of functions that return a CHARACTER representation of the input variable. Definition char_utilities.F90:253 Function to check whether a value is missing or not. Definition missing_values.f90:72 Module for defining the extension and coordinates of a rectangular georeferenced grid. Definition grid_dim_class.F90:211 Definitions of constants and functions for working with missing values. Definition missing_values.f90:50 Module for quickly interpreting the OPTIONAL parameters passed to a subprogram. Definition optional_values.f90:28 Derived type describing the extension of a grid and the geographical coordinates of each point. Definition grid_dim_class.F90:221 |