libsim Versione 7.2.1

◆ grid_dim_read_unit()

subroutine, private grid_dim_read_unit ( type(grid_dim), intent(out)  this,
integer, intent(in)  unit 
)
private

This method reads from a Fortran file unit the contents of the object this.

The record to be read must have been written with the ::write_unit method. The method works both on formatted and unformatted files.

Parametri
[out]thisobject to be read
[in]unitunit from which to read, it must be an opened Fortran file unit

Definizione alla linea 343 del file grid_dim_class.F90.

344! Copyright (C) 2010 ARPA-SIM <urpsim@smr.arpa.emr.it>
345! authors:
346! Davide Cesari <dcesari@arpa.emr.it>
347! Paolo Patruno <ppatruno@arpa.emr.it>
348
349! This program is free software; you can redistribute it and/or
350! modify it under the terms of the GNU General Public License as
351! published by the Free Software Foundation; either version 2 of
352! the License, or (at your option) any later version.
353
354! This program is distributed in the hope that it will be useful,
355! but WITHOUT ANY WARRANTY; without even the implied warranty of
356! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
357! GNU General Public License for more details.
358
359! You should have received a copy of the GNU General Public License
360! along with this program. If not, see <http://www.gnu.org/licenses/>.
361#include "config.h"
362
366MODULE grid_dim_class
370USE err_handling
371IMPLICIT NONE
372
376TYPE grid_dim
377 INTEGER :: nx
378 INTEGER :: ny
379 DOUBLE PRECISION,POINTER :: lat(:,:)
380 DOUBLE PRECISION,POINTER :: lon(:,:)
381END TYPE grid_dim
382
383INTERFACE delete
384 MODULE PROCEDURE grid_dim_delete
385END INTERFACE
386
387INTERFACE copy
388 MODULE PROCEDURE grid_dim_copy
389END INTERFACE
390
391INTERFACE alloc
392 MODULE PROCEDURE grid_dim_alloc
393END INTERFACE
394
395INTERFACE dealloc
396 MODULE PROCEDURE grid_dim_dealloc
397END INTERFACE
398
399INTERFACE OPERATOR (==)
400 MODULE PROCEDURE grid_dim_eq
401END INTERFACE
402
403INTERFACE write_unit
404 MODULE PROCEDURE grid_dim_write_unit
405END INTERFACE
406
407INTERFACE read_unit
408 MODULE PROCEDURE grid_dim_read_unit
409END INTERFACE
410
411INTERFACE display
412 MODULE PROCEDURE grid_dim_display
413END INTERFACE
414
415PRIVATE grid_dim_delete, grid_dim_copy, grid_dim_alloc, grid_dim_dealloc, &
416 grid_dim_eq, grid_dim_read_unit, grid_dim_write_unit, grid_dim_display
417
418CONTAINS
419
420FUNCTION grid_dim_new(nx, ny) RESULT(this)
421INTEGER, INTENT(in), OPTIONAL :: nx, ny
422
423TYPE(grid_dim) :: this
424
425this%nx = optio_l(nx)
426this%ny = optio_l(ny)
427NULLIFY(this%lat, this%lon)
428
429END FUNCTION grid_dim_new
430
431
432SUBROUTINE grid_dim_delete(this)
433TYPE(grid_dim), INTENT(inout) :: this
434
435CALL dealloc(this)
436this%nx = imiss
437this%ny = imiss
438
439END SUBROUTINE grid_dim_delete
440
441
442SUBROUTINE grid_dim_alloc(this)
443TYPE(grid_dim),INTENT(inout) :: this
444
445IF (ASSOCIATED(this%lon) .AND. ASSOCIATED(this%lat)) THEN
446 IF (SIZE(this%lon, 1) == this%nx .AND. SIZE(this%lon, 2) == this%ny .AND. &
447 SIZE(this%lat, 1) == this%nx .AND. SIZE(this%lat, 2) == this%ny) RETURN
448ENDIF
449CALL dealloc(this)
450IF (c_e(this%nx) .AND. c_e(this%ny)) THEN
451 ALLOCATE(this%lon(this%nx, this%ny), this%lat(this%nx, this%ny))
452ENDIF
453
454END SUBROUTINE grid_dim_alloc
455
456
457SUBROUTINE grid_dim_dealloc(this)
458TYPE(grid_dim),INTENT(inout) :: this
459
460IF (ASSOCIATED(this%lon)) DEALLOCATE(this%lon)
461IF (ASSOCIATED(this%lat)) DEALLOCATE(this%lat)
462
463END SUBROUTINE grid_dim_dealloc
464
465
466SUBROUTINE grid_dim_copy(this, that)
467TYPE(grid_dim),INTENT(in) :: this
468TYPE(grid_dim),INTENT(out) :: that
469
470that = grid_dim_new(this%nx, this%ny)
471
472IF (ASSOCIATED(this%lon) .AND. ASSOCIATED(this%lat))THEN
473 CALL alloc(that)
474
475#ifdef DEBUG
476 IF (SIZE(this%lon,1) /= this%nx .OR. SIZE(this%lon,2) /= this%ny) THEN
477 CALL raise_error('grid_dim_copy, dimensioni non valide: '// &
478 trim(to_char(SIZE(this%lon,1)))//' '//trim(to_char(this%nx))// &
479 trim(to_char(SIZE(this%lon,2)))//' '//trim(to_char(this%ny)))
480 ENDIF
481 IF (SIZE(this%lat,1) /= this%nx .OR. SIZE(this%lat,2) /= this%ny) THEN
482 CALL raise_error('grid_dim_copy, dimensioni non valide: '// &
483 trim(to_char(SIZE(this%lat,1)))//' '//trim(to_char(this%nx))// &
484 trim(to_char(SIZE(this%lat,2)))//' '//trim(to_char(this%ny)))
485 ENDIF
486#endif
487
488 that%lon(:,:) = this%lon(:,:)
489 that%lat(:,:) = this%lat(:,:)
490ENDIF
491
492END SUBROUTINE grid_dim_copy
493
494
495ELEMENTAL FUNCTION grid_dim_eq(this, that) RESULT(res)
496TYPE(grid_dim),INTENT(IN) :: this, that
497LOGICAL :: res
498
499res = this%nx == that%nx .and. &
500 this%ny == that%ny
501
502END FUNCTION grid_dim_eq
503
504
509SUBROUTINE grid_dim_read_unit(this, unit)
510TYPE(grid_dim),INTENT(out) :: this
511INTEGER, INTENT(in) :: unit
512
513CHARACTER(len=40) :: form
514LOGICAL :: is_all
515
516INQUIRE(unit, form=form)
517IF (form == 'FORMATTED') THEN
518 READ(unit,*)this%nx,this%ny
519 READ(unit,*)is_all
520 IF (is_all) THEN
521 CALL alloc(this)
522 READ(unit,*)this%lon,this%lat
523 ELSE
524 READ(unit,*)
525 ENDIF
526ELSE
527 READ(unit)this%nx,this%ny
528 READ(unit)is_all
529 IF (is_all) THEN
530 CALL alloc(this)
531 READ(unit)this%lon,this%lat
532 ELSE
533 READ(unit)
534 ENDIF
535ENDIF
536
537END SUBROUTINE grid_dim_read_unit
538
539
544SUBROUTINE grid_dim_write_unit(this, unit)
545TYPE(grid_dim),INTENT(in) :: this
546INTEGER, INTENT(in) :: unit
547
548CHARACTER(len=40) :: form
549LOGICAL :: is_all
550
551INQUIRE(unit, form=form)
552IF (form == 'FORMATTED') THEN
553 WRITE(unit,*)this%nx,this%ny
554 is_all = (ASSOCIATED(this%lon) .AND. ASSOCIATED(this%lat))
555 WRITE(unit,*)is_all
556 IF (is_all) THEN
557 WRITE(unit,*)this%lon,this%lat
558 ELSE
559 WRITE(unit,*)
560 ENDIF
561ELSE
562 WRITE(unit)this%nx,this%ny
563 is_all = (ASSOCIATED(this%lon) .AND. ASSOCIATED(this%lat))
564 WRITE(unit)is_all
565 IF (is_all) THEN
566 WRITE(unit)this%lon,this%lat
567 ELSE
568 WRITE(unit)
569 ENDIF
570ENDIF
571
572END SUBROUTINE grid_dim_write_unit
573
574
576SUBROUTINE grid_dim_display(this)
577TYPE(grid_dim),INTENT(in) :: this
578
579print*,'Number of points along x direction',this%nx
580print*,'Number of points along y direction',this%ny
581
582END SUBROUTINE grid_dim_display
583
584END MODULE grid_dim_class
Set of functions that return a CHARACTER representation of the input variable.
Function to check whether a value is missing or not.
Utilities for CHARACTER variables.
Gestione degli errori.
Module for defining the extension and coordinates of a rectangular georeferenced grid.
Definitions of constants and functions for working with missing values.
Module for quickly interpreting the OPTIONAL parameters passed to a subprogram.
Derived type describing the extension of a grid and the geographical coordinates of each point.

Generated with Doxygen.