libsim Versione 7.1.11

◆ 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 349 del file grid_dim_class.F90.

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