libsim Versione 7.2.6
|
◆ grid_file_id_new()
Constructor for the grid_file_id class. It opens the associated file(s); the driver to be used for file access is selected according to the filename argument, to the optional argument driver, or to the optional argument from_grid_id, with increasing priority. If driver and from_grid_id are not provided and filename does not contain driver information, a default is chosen. If filename is an empty string or missing value, the object will be empty, the same will happen in case the file cannot be successfully opened. This condition can be tested with the function c_e() . The driver string provided with the filename can also contain driver-specific options separated by commas, e.g.
Definizione alla linea 409 del file grid_id_class.F90. 410!> Constructor for the \a grid_id class. It gets the next grid (grib
411!! message or raster band) from the file_id provided. If the file
412!! associated to the file_id provided contains no more grids, or if
413!! the argument \a file_id is not provided, an empty object is
414!! created; this condition can be tested with the function c_e().
415!! Alternative ways to define the object (to be used in rare cases)
416!! are through a grib_api template file name (\a grib_api_template
417!! argument) or through a grib_api integer id obtained directly from
418!! grib_api calls (\a grib_api_id argument).
419FUNCTION grid_id_new(from_grid_file_id, grib_api_template, grib_api_id, &
420 no_driver_id) RESULT(this)
421TYPE(grid_file_id),INTENT(inout),OPTIONAL,TARGET :: from_grid_file_id !< file object from which grid object has to be created
422CHARACTER(len=*),INTENT(in),OPTIONAL :: grib_api_template !< grib_api template file from which grid_object has to be created
423INTEGER,INTENT(in),OPTIONAL :: grib_api_id !< grib_api id obtained directly from a \a grib_get subroutine call
424INTEGER,INTENT(in),OPTIONAL :: no_driver_id
425TYPE(grid_id) :: this
426
427INTEGER :: ier
428
429#ifdef HAVE_LIBGDAL
430CALL gdalnullify(this%gdalid)
431#endif
432
433IF (PRESENT(from_grid_file_id)) THEN
434 this%driver = from_grid_file_id%driver ! take driver from file_id
435
436#ifdef HAVE_LIBGRIBAPI
437 IF (this%driver == grid_id_grib_api) THEN
438 IF (c_e(from_grid_file_id%gaid)) THEN
439 CALL grib_new_from_file(from_grid_file_id%gaid, this%gaid, ier)
440 IF (ier /= grib_success) this%gaid = imiss
441 ENDIF
442 ENDIF
443#endif
444#ifdef HAVE_LIBGDAL
445 IF (this%driver == grid_id_gdal) THEN
446 IF (gdalassociated(from_grid_file_id%gdalid) .AND. &
447 ASSOCIATED(from_grid_file_id%file_id_copy)) THEN
448 IF (from_grid_file_id%nlastband < &
449 gdalgetrastercount(from_grid_file_id%gdalid)) THEN ! anything to read?
450 from_grid_file_id%nlastband = from_grid_file_id%nlastband + 1
451 this%gdalid = &
452 gdalgetrasterband(from_grid_file_id%gdalid, from_grid_file_id%nlastband)
453 this%file_id => from_grid_file_id%file_id_copy ! for gdal remember copy of file_id
454
455 ENDIF
456 ENDIF
457 ENDIF
458#endif
459
460#ifdef HAVE_LIBGRIBAPI
461ELSE IF (PRESENT(grib_api_template)) THEN
462 this%driver = grid_id_grib_api
463 CALL grib_new_from_samples(this%gaid, grib_api_template, ier)
464 IF (ier /= grib_success) this%gaid = imiss
465ELSE IF (PRESENT(grib_api_id)) THEN
466 this%driver = grid_id_grib_api
467 this%gaid = grib_api_id
468#endif
469ELSE IF (PRESENT(no_driver_id)) THEN
470 this%driver = grid_id_no_driver
471 this%nodriverid = no_driver_id
472ENDIF
473
474END FUNCTION grid_id_new
475
476
477!> Destructor for the \a grid_id class. It releases the memory associated with
478!! the grid descriptor identifier. In grib_api this is necessary and
479!! can be made also after closing the corresponding \a grid_file_id
480!! object; while for gdal this is a no-operation.
481SUBROUTINE grid_id_delete(this)
482TYPE(grid_id),INTENT(inout) :: this !< object to be deleted
483
484this%nodriverid = imiss
485#ifdef HAVE_LIBGRIBAPI
486IF (this%driver == grid_id_grib_api) THEN
487 IF (c_e(this%gaid)) CALL grib_release(this%gaid)
|