libsim Versione 7.1.11
|
◆ grid_dim_write_unit()
This method writes on a Fortran file unit the contents of the object this. The record can successively be read by the ::read_unit method. The method works both on formatted and unformatted files.
Definizione alla linea 384 del file grid_dim_class.F90. 385! Copyright (C) 2010 ARPA-SIM <urpsim@smr.arpa.emr.it>
386! authors:
387! Davide Cesari <dcesari@arpa.emr.it>
388! Paolo Patruno <ppatruno@arpa.emr.it>
389
390! This program is free software; you can redistribute it and/or
391! modify it under the terms of the GNU General Public License as
392! published by the Free Software Foundation; either version 2 of
393! the License, or (at your option) any later version.
394
395! This program is distributed in the hope that it will be useful,
396! but WITHOUT ANY WARRANTY; without even the implied warranty of
397! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
398! GNU General Public License for more details.
399
400! You should have received a copy of the GNU General Public License
401! along with this program. If not, see <http://www.gnu.org/licenses/>.
402#include "config.h"
403
412IMPLICIT NONE
413
418 INTEGER :: nx
419 INTEGER :: ny
420 DOUBLE PRECISION,POINTER :: lat(:,:)
421 DOUBLE PRECISION,POINTER :: lon(:,:)
423
424INTERFACE delete
425 MODULE PROCEDURE grid_dim_delete
426END INTERFACE
427
428INTERFACE copy
429 MODULE PROCEDURE grid_dim_copy
430END INTERFACE
431
432INTERFACE alloc
433 MODULE PROCEDURE grid_dim_alloc
434END INTERFACE
435
436INTERFACE dealloc
437 MODULE PROCEDURE grid_dim_dealloc
438END INTERFACE
439
440INTERFACE OPERATOR (==)
441 MODULE PROCEDURE grid_dim_eq
442END INTERFACE
443
444INTERFACE write_unit
445 MODULE PROCEDURE grid_dim_write_unit
446END INTERFACE
447
448INTERFACE read_unit
449 MODULE PROCEDURE grid_dim_read_unit
450END INTERFACE
451
452INTERFACE display
453 MODULE PROCEDURE grid_dim_display
454END INTERFACE
455
456PRIVATE grid_dim_delete, grid_dim_copy, grid_dim_alloc, grid_dim_dealloc, &
457 grid_dim_eq, grid_dim_read_unit, grid_dim_write_unit, grid_dim_display
458
459CONTAINS
460
461FUNCTION grid_dim_new(nx, ny) RESULT(this)
462INTEGER, INTENT(in), OPTIONAL :: nx, ny
463
464TYPE(grid_dim) :: this
465
466this%nx = optio_l(nx)
467this%ny = optio_l(ny)
468NULLIFY(this%lat, this%lon)
469
470END FUNCTION grid_dim_new
471
472
473SUBROUTINE grid_dim_delete(this)
474TYPE(grid_dim), INTENT(inout) :: this
475
476CALL dealloc(this)
477this%nx = imiss
478this%ny = imiss
479
480END SUBROUTINE grid_dim_delete
481
482
483SUBROUTINE grid_dim_alloc(this)
484TYPE(grid_dim),INTENT(inout) :: this
485
486IF (ASSOCIATED(this%lon) .AND. ASSOCIATED(this%lat)) THEN
487 IF (SIZE(this%lon, 1) == this%nx .AND. SIZE(this%lon, 2) == this%ny .AND. &
488 SIZE(this%lat, 1) == this%nx .AND. SIZE(this%lat, 2) == this%ny) RETURN
489ENDIF
490CALL dealloc(this)
492 ALLOCATE(this%lon(this%nx, this%ny), this%lat(this%nx, this%ny))
493ENDIF
494
495END SUBROUTINE grid_dim_alloc
496
497
498SUBROUTINE grid_dim_dealloc(this)
499TYPE(grid_dim),INTENT(inout) :: this
500
501IF (ASSOCIATED(this%lon)) DEALLOCATE(this%lon)
502IF (ASSOCIATED(this%lat)) DEALLOCATE(this%lat)
503
504END SUBROUTINE grid_dim_dealloc
505
506
507SUBROUTINE grid_dim_copy(this, that)
508TYPE(grid_dim),INTENT(in) :: this
509TYPE(grid_dim),INTENT(out) :: that
510
511that = grid_dim_new(this%nx, this%ny)
512
513IF (ASSOCIATED(this%lon) .AND. ASSOCIATED(this%lat))THEN
514 CALL alloc(that)
515
516#ifdef DEBUG
517 IF (SIZE(this%lon,1) /= this%nx .OR. SIZE(this%lon,2) /= this%ny) THEN
518 CALL raise_error('grid_dim_copy, dimensioni non valide: '// &
521 ENDIF
522 IF (SIZE(this%lat,1) /= this%nx .OR. SIZE(this%lat,2) /= this%ny) THEN
523 CALL raise_error('grid_dim_copy, dimensioni non valide: '// &
526 ENDIF
527#endif
528
529 that%lon(:,:) = this%lon(:,:)
530 that%lat(:,:) = this%lat(:,:)
531ENDIF
532
533END SUBROUTINE grid_dim_copy
534
535
536ELEMENTAL FUNCTION grid_dim_eq(this, that) RESULT(res)
537TYPE(grid_dim),INTENT(IN) :: this, that
538LOGICAL :: res
539
540res = this%nx == that%nx .and. &
541 this%ny == that%ny
542
543END FUNCTION grid_dim_eq
544
545
550SUBROUTINE grid_dim_read_unit(this, unit)
551TYPE(grid_dim),INTENT(out) :: this
552INTEGER, INTENT(in) :: unit
553
554CHARACTER(len=40) :: form
555LOGICAL :: is_all
556
557INQUIRE(unit, form=form)
558IF (form == 'FORMATTED') THEN
559 READ(unit,*)this%nx,this%ny
560 READ(unit,*)is_all
561 IF (is_all) THEN
562 CALL alloc(this)
563 READ(unit,*)this%lon,this%lat
564 ELSE
565 READ(unit,*)
566 ENDIF
567ELSE
568 READ(unit)this%nx,this%ny
569 READ(unit)is_all
570 IF (is_all) THEN
571 CALL alloc(this)
572 READ(unit)this%lon,this%lat
573 ELSE
574 READ(unit)
575 ENDIF
576ENDIF
577
578END SUBROUTINE grid_dim_read_unit
579
580
585SUBROUTINE grid_dim_write_unit(this, unit)
586TYPE(grid_dim),INTENT(in) :: this
587INTEGER, INTENT(in) :: unit
588
589CHARACTER(len=40) :: form
590LOGICAL :: is_all
591
592INQUIRE(unit, form=form)
593IF (form == 'FORMATTED') THEN
594 WRITE(unit,*)this%nx,this%ny
595 is_all = (ASSOCIATED(this%lon) .AND. ASSOCIATED(this%lat))
596 WRITE(unit,*)is_all
597 IF (is_all) THEN
598 WRITE(unit,*)this%lon,this%lat
599 ELSE
600 WRITE(unit,*)
601 ENDIF
602ELSE
603 WRITE(unit)this%nx,this%ny
604 is_all = (ASSOCIATED(this%lon) .AND. ASSOCIATED(this%lat))
605 WRITE(unit)is_all
606 IF (is_all) THEN
607 WRITE(unit)this%lon,this%lat
608 ELSE
609 WRITE(unit)
610 ENDIF
611ENDIF
612
613END SUBROUTINE grid_dim_write_unit
614
615
617SUBROUTINE grid_dim_display(this)
618TYPE(grid_dim),INTENT(in) :: this
619
620print*,'Number of points along x direction',this%nx
621print*,'Number of points along y direction',this%ny
622
623END SUBROUTINE grid_dim_display
624
Set of functions that return a CHARACTER representation of the input variable. Definition: char_utilities.F90:259 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:217 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:227 |