libsim Versione 7.2.1

◆ grid_file_id_new()

type(grid_file_id) function grid_file_id_new ( character(len=*), intent(in) filename,
character(len=*), intent(in) mode,
integer, intent(in), optional driver,
type(grid_id), intent(in), optional from_grid_id )
private

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. 'gdal,8,44,10,46:globe.dat'.

Parametri
[in]filenamename of file containing gridded data, in the format [driver:]pathname
[in]modeaccess mode for file, 'r' or 'w'
[in]driverselect the driver that will be associated to the grid_file_id created, use the constants grid_id_notype, grid_id_grib_api, grid_id_gdal
[in]from_grid_idselect the driver as the one associated to the provided grid_id object

Definizione alla linea 409 del file grid_id_class.F90.

410
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
422CHARACTER(len=*),INTENT(in),OPTIONAL :: grib_api_template
423INTEGER,INTENT(in),OPTIONAL :: grib_api_id
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
481SUBROUTINE grid_id_delete(this)
482TYPE(grid_id),INTENT(inout) :: this
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)

Generated with Doxygen.