libsim  Versione 7.1.9

◆ grid_file_id_new()

type(grid_file_id) function grid_id_class::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 
)

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 415 del file grid_id_class.F90.

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).
419 FUNCTION grid_id_new(from_grid_file_id, grib_api_template, grib_api_id, &
420  no_driver_id) RESULT(this)
421 TYPE(grid_file_id),INTENT(inout),OPTIONAL,TARGET :: from_grid_file_id
422 CHARACTER(len=*),INTENT(in),OPTIONAL :: grib_api_template
423 INTEGER,INTENT(in),OPTIONAL :: grib_api_id
424 INTEGER,INTENT(in),OPTIONAL :: no_driver_id
425 TYPE(grid_id) :: this
426 
427 INTEGER :: ier
428 
429 #ifdef HAVE_LIBGDAL
430 CALL gdalnullify(this%gdalid)
431 #endif
432 
433 IF (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
461 ELSE 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
465 ELSE IF (PRESENT(grib_api_id)) THEN
466  this%driver = grid_id_grib_api
467  this%gaid = grib_api_id
468 #endif
469 ELSE IF (PRESENT(no_driver_id)) THEN
470  this%driver = grid_id_no_driver
471  this%nodriverid = no_driver_id
472 ENDIF
473 
474 END FUNCTION grid_id_new
475 
476 
481 SUBROUTINE grid_id_delete(this)
482 TYPE(grid_id),INTENT(inout) :: this
483 
484 this%nodriverid = imiss
485 #ifdef HAVE_LIBGRIBAPI
486 IF (this%driver == grid_id_grib_api) THEN
487  IF (c_e(this%gaid)) CALL grib_release(this%gaid)
488 ENDIF
489 this%gaid = imiss
490 #endif
491 #ifdef HAVE_LIBGDAL
492 CALL gdalnullify(this%gdalid)
493 NULLIFY(this%file_id)

Generated with Doxygen.