|
libsim Versione 8.0.0
|
◆ import_from_gridinfo()
Import a single gridinfo object into a volgrid6d object. This methods imports a single gridded field from a gridinfo object into a volgrid6d object, inserting it into the multidimensional structure of volgrid6d. The volgrid6d object must have been already initialized and the dimensions specified with volgrid6d_alloc(). If the force argument is missing or .FALSE. , the volgrid6d object dimension descriptors (time, timerange, vertical level, physical variable) must already have space for the corresponding values coming from gridinfo, otherwise the object will be rejected; this means that all the volgrid6d dimension descriptors should be correctly assigned. If force is .TRUE. , the gridinfo dimension descriptors that do not fit into available descriptors in the volgrid6d structure, will be accomodated in a empty (i.e. equal to missing value) descriptor, if available, otherwise the gridinfo will be rejected. The descriptor of the grid in the volgrid object is assigned to the descriptor contained in gridinfo if it is missing in volgrid, otherwise it is checked and the object is rejected if grids do not match.
Definizione alla linea 1014 del file volgrid6d_class.F90. 1016 CALL copy(gaid_template, gaid)
1017#ifdef DEBUG
1018 CALL l4f_category_log(this%category,l4f_debug,"template cloned to a new gaid")
1019#endif
1020 usetemplate = c_e(gaid)
1021ENDIF
1022
1023IF (.NOT.usetemplate) THEN
1024 IF (optio_log(clone)) THEN
1025 CALL copy(this%gaid(ilevel,itime,itimerange,ivar), gaid)
1026#ifdef DEBUG
1027 CALL l4f_category_log(this%category,l4f_debug,"original gaid cloned to a new one")
1028#endif
1029 ELSE
1030 gaid = this%gaid(ilevel,itime,itimerange,ivar)
1031 ENDIF
1032ENDIF
1033
1034IF (this%time_definition == 1 .OR. this%time_definition == 2) THEN
1035 correctedtime = this%time(itime) - &
1036 timedelta_new(sec=this%timerange(itimerange)%p1)
1037ELSE
1038 correctedtime = this%time(itime)
1039ENDIF
1040
1041CALL init(gridinfo,gaid, this%griddim, correctedtime, this%timerange(itimerange), &
1042 this%level(ilevel), this%var(ivar))
1043
1044! reset the gridinfo, bad but necessary at this point for encoding the field
1045CALL export(gridinfo%griddim, gridinfo%gaid)
1046! encode the field
1047IF (ASSOCIATED(this%voldati)) THEN
1048 CALL encode_gridinfo(gridinfo, this%voldati(:,:,ilevel,itime,itimerange,ivar))
1049ELSE IF (usetemplate) THEN ! field must be forced into template in this case
1050 NULLIFY(voldati)
1051 CALL volgrid_get_vol_2d(this, ilevel, itime, itimerange, ivar, voldati)
1052 CALL encode_gridinfo(gridinfo, voldati)
1053 DEALLOCATE(voldati)
1054ENDIF
1055
1056END SUBROUTINE export_to_gridinfo
1057
1058
1059!> Import an array of \a gridinfo objects into an array of \a
1060!! volgrid6d objects.
1061!! This method imports an array of gridded fields from an \a
1062!! arrayof_gridinfo object into a suitable number of \a volgrid6d
1063!! objects. The number of \a volgrid6d allocated is determined by the
1064!! number of different grids encountered in \a arrayof_gridinfo.
1065!! Unlike the import for a single \a gridinfo, here the \a volgrid6d
1066!! object is a non-associated pointer to a 1-d array of uninitialized
1067!! objects, and all the dimension descriptors in each of the objects
1068!! are allocated and assigned within the method according to the data
1069!! contained in \a gridinfov.
1070!! If the \a anavar array argument is provided, all the input messages
1071!! whose variable maps to one of the B-table variables contained in \a
1072!! anavar are treated as time-independent (AKA anagraphic data,
1073!! station data, etc.), thus their time and timerange are ignored and
1074!! they are replicated for every time and timerange present in the
1075!! corresponding data volume.
1076SUBROUTINE import_from_gridinfovv(this, gridinfov, dup_mode, clone, decode, &
1077 time_definition, anavar, categoryappend)
1078TYPE(volgrid6d),POINTER :: this(:) !< object in which to import
1079TYPE(arrayof_gridinfo),INTENT(in) :: gridinfov !< array of gridinfo objects to be imported
1080INTEGER,INTENT(in),OPTIONAL :: dup_mode !< determines the behavior in case of duplicate metadata: if \a dup_mode is not provided or 0, a duplicate field overwrites, if \a dup_mode is 1, duplicate fields are merged with priority to the last
1081LOGICAL , INTENT(in),OPTIONAL :: clone !< if provided and \c .TRUE. , clone the gaid's from \a gridinfo to \a this
1082LOGICAL,INTENT(in),OPTIONAL :: decode !< if provided and \a .FALSE. the data volume in the elements of \a this is not allocated and successive work will be performed on grid_id's
1083INTEGER,INTENT(IN),OPTIONAL :: time_definition !< 0=time is reference time; 1=time is validity time
1084CHARACTER(len=*),INTENT(IN),OPTIONAL :: anavar(:) !< list of variables (B-table code equivalent) to be treated as time-independent data
1085CHARACTER(len=*),INTENT(in),OPTIONAL :: categoryappend !< append this suffix to log4fortran namespace category
1086
1087INTEGER :: i, j, stallo
1088INTEGER :: ngrid, ntime, ntimerange, nlevel, nvar, ltime_definition
1089TYPE(l4f_handle) :: category
1090CHARACTER(len=512) :: a_name
1091TYPE(datetime),ALLOCATABLE :: correctedtime(:)
1092LOGICAL,ALLOCATABLE :: isanavar(:)
1093TYPE(vol7d_var) :: lvar
1094TYPE(vol7d_timerange),ALLOCATABLE :: correctedtimerange(:)
1095
1096! category temporanea (altrimenti non possiamo loggare)
1097if (present(categoryappend))then
1098 call l4f_launcher(a_name,a_name_append=trim(subcategory)//"."//trim(categoryappend))
1099else
1100 call l4f_launcher(a_name,a_name_append=trim(subcategory))
1101endif
1102category=l4f_category_get_handle(a_name)
1103
1104#ifdef DEBUG
1105call l4f_category_log(category,l4f_debug,"start import_from_gridinfovv")
1106#endif
1107
1108IF (PRESENT(time_definition)) THEN
1109 ltime_definition = max(min(time_definition, 2), 0)
1110ELSE
1111 ltime_definition = 0
1112ENDIF
1113
1114ngrid=count_distinct(gridinfov%array(1:gridinfov%arraysize)%griddim,back=.true.)
1115CALL l4f_category_log(category,l4f_info, t2c(ngrid)// &
1116 ' different grid definition(s) found in input data')
1117
1118ALLOCATE(this(ngrid),stat=stallo)
1119IF (stallo /= 0)THEN
1120 CALL l4f_category_log(category,l4f_fatal,"allocating memory")
1121 CALL raise_fatal_error()
1122ENDIF
1123DO i = 1, ngrid
1124 IF (PRESENT(categoryappend))THEN
1125 CALL init(this(i), time_definition=ltime_definition, categoryappend=trim(categoryappend)//"-vol"//t2c(i))
1126 ELSE
1127 CALL init(this(i), time_definition=ltime_definition, categoryappend="vol"//t2c(i))
1128 ENDIF
1129ENDDO
1130
1131this(:)%griddim=pack_distinct(gridinfov%array(1:gridinfov%arraysize)%griddim, &
1132 ngrid, back=.true.)
1133
1134! mark elements as ana variables (time-independent)
1135ALLOCATE(isanavar(gridinfov%arraysize))
1136isanavar(:) = .false.
1137IF (PRESENT(anavar)) THEN
1138 DO i = 1, gridinfov%arraysize
1139 DO j = 1, SIZE(anavar)
1140 lvar = convert(gridinfov%array(i)%var)
1141 IF (lvar%btable == anavar(j)) THEN
1142 isanavar(i) = .true.
1143 EXIT
1144 ENDIF
1145 ENDDO
1146 ENDDO
1147 CALL l4f_category_log(category,l4f_info,t2c(count(isanavar))//'/'// &
1148 t2c(gridinfov%arraysize)//' constant-data messages found in input data')
1149ENDIF
1150
1151IF (ltime_definition == 1 .OR. ltime_definition == 2) THEN ! verification time
1152 ALLOCATE(correctedtime(gridinfov%arraysize))
1153 correctedtime(:) = gridinfov%array(1:gridinfov%arraysize)%time
1154 DO i = 1, gridinfov%arraysize
1155 correctedtime(i) = correctedtime(i) + &
1156 timedelta_new(sec=gridinfov%array(i)%timerange%p1)
1157 ENDDO
1158ENDIF
1159IF (ltime_definition == 2) THEN ! set all to analysis
1160 ALLOCATE(correctedtimerange(gridinfov%arraysize))
1161 correctedtimerange(:) = gridinfov%array(1:gridinfov%arraysize)%timerange
1162 correctedtimerange(:)%p1 = 0
1163ENDIF
1164
1165DO i = 1, ngrid
1166 IF (PRESENT(anavar)) THEN
1167 j = count((this(i)%griddim == gridinfov%array(1:gridinfov%arraysize)%griddim) &
|