- Timestamp:
- Oct 16, 2019, 4:11:34 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/module_generic.f90
r2618 r2724 5 5 ! continguos_homogene_zones: Subroutine to look for contiguous zones by looking by continuous grid points 6 6 ! freeunit: provides the number of a free unit in which open a file 7 ! fill_matrix2DRK_winmat2D_list1D: Subroutine to fill a 2D RK matrix using a list of 1D indices from 8 ! another given 2D matrix 7 9 ! from_coordlist_2DRKmatrix: Subroutine to construct a 2D RK matrix from a list of values accompaigned 8 10 ! by a list of coordinates to find i,j grid-point coordinates by minimum distance … … 21 23 ! Index2DArrayR: Function to provide the first index of a given value inside a 2D real array 22 24 ! Index2DArrayR_K: Function to provide the first index of a given value inside a 2D real(r_k) array 25 ! index_samevals1D_RK: Subroutine to search for the indices of the same values between 2 1D RK series 26 ! of values allowing repetitions 27 ! index_samevals2D_RK: Subroutine to search for the indices of the same values between 2 2D RK series 28 ! of values allowing repetitions 23 29 ! JD: Fucntion to compute the julian date (JD) given a gregorian calendar 24 30 ! Nvalues_2DArrayI: Number of different values of a 2D integer array … … 1229 1235 END SUBROUTINE rm_values_vecRK 1230 1236 1237 SUBROUTINE index_samevals1D_RK(d1r, refv, d1v, vals, ii, indices, samevalues) 1238 ! Subroutine to search for the indices of the same values between 2 1D RK series of values allowing 1239 ! repetitions 1240 1241 IMPLICIT NONE 1242 1243 INTEGER, INTENT(in) :: d1r, d1v 1244 REAL(r_k), DIMENSION(d1r), INTENT(in) :: refv 1245 REAL(r_k), DIMENSION(d1v), INTENT(in) :: vals 1246 INTEGER, INTENT(out) :: ii 1247 INTEGER, DIMENSION(d1v,2), INTENT(out) :: indices 1248 REAL(r_k), DIMENSION(d1v), INTENT(out) :: samevalues 1249 1250 ! Local 1251 INTEGER :: ir, iv, iiv 1252 1253 !!!!!!! Variables 1254 ! d1r: size of the reference data 1255 ! refv: reference values 1256 ! d1v: size of the values 1257 ! vals: values to look in 1258 ! ii: quantity of same values found 1259 ! indices: output 1260 ! samevalues: values where coincidence is found 1261 1262 fname = 'index_samevals1D_RK' 1263 1264 indices = 0 1265 samevalues = zeroRK 1266 ii = 0 1267 DO ir=1, d1r 1268 DO iv=1, d1v 1269 IF (vals(iv) == refv(ir)) THEN 1270 ii = ii + 1 1271 indices(ii,:) = (/ ir, iv /) 1272 samevalues(ii) = refv(ir) 1273 END IF 1274 END DO 1275 END DO 1276 1277 RETURN 1278 1279 END SUBROUTINE index_samevals1D_RK 1280 1281 SUBROUTINE index_samevals2D_RK(d1r, d2r, refv, d1v, d2v, d12v, vals, ii, indices, samevalues) 1282 ! Subroutine to search for the indices of the same values between 2 2D RK series of values allowing 1283 ! repetitions 1284 1285 IMPLICIT NONE 1286 1287 INTEGER, INTENT(in) :: d1r, d2r, d1v, d2v, d12v 1288 REAL(r_k), DIMENSION(d1r,d2r), INTENT(in) :: refv 1289 REAL(r_k), DIMENSION(d1v,d2v), INTENT(in) :: vals 1290 INTEGER, INTENT(out) :: ii 1291 INTEGER, DIMENSION(d12v,2,2), INTENT(out) :: indices 1292 REAL(r_k), DIMENSION(d12v), INTENT(out) :: samevalues 1293 1294 ! Local 1295 INTEGER :: ir1, ir2, iv1, iv2 1296 1297 !!!!!!! Variables 1298 ! d1r, d2r: size of the reference data 1299 ! refv: reference values 1300 ! d1v, d2v: size of the values 1301 ! vals: values to look in 1302 ! ii: quantity of same values found 1303 ! indices: output 1304 ! samevalues: values where coincidence is found 1305 1306 fname = 'index_samevals2D_RK' 1307 1308 indices = 0 1309 samevalues = zeroRK 1310 ii = 0 1311 DO ir1=1, d1r 1312 DO ir2=1, d2r 1313 DO iv1=1, d1v 1314 DO iv2=1, d2v 1315 IF (vals(iv1,iv2) == refv(ir1,ir2)) THEN 1316 ii = ii + 1 1317 indices(ii,1,1) = ir1 1318 indices(ii,1,2) = ir2 1319 indices(ii,2,1) = iv1 1320 indices(ii,2,2) = iv2 1321 samevalues(ii) = refv(ir1,ir2) 1322 END IF 1323 END DO 1324 END DO 1325 END DO 1326 END DO 1327 1328 RETURN 1329 1330 END SUBROUTINE index_samevals2D_RK 1331 1332 SUBROUTINE fill_matrix2DRK_winmat2D_list1D(d1i, d2i, inmatrix, ind, dlist, inlist, olist, missval, & 1333 od, d1o, d2o, omat) 1334 ! Subroutine to fill a 2D RK matrix using a list of 1D indices from another given 2D matrix 1335 1336 IMPLICIT NONE 1337 1338 INTEGER, INTENT(in) :: d1i, d2i, ind, dlist, od, d1o, d2o 1339 REAL(r_k), DIMENSION(d1i, d2i), INTENT(in) :: inmatrix 1340 INTEGER, DIMENSION(dlist), INTENT(in) :: inlist, olist 1341 REAL(r_k), INTENT(in) :: missval 1342 REAL(r_k), DIMENSION(d1o, d2o), INTENT(out) :: omat 1343 1344 ! Local 1345 INTEGER :: ii, ij, oi, oj, il 1346 INTEGER :: isame, osame, irun, orun 1347 INTEGER :: ilx, olx 1348 CHARACTER(len=3) :: isS, osS 1349 1350 !!!!!!! Variables 1351 ! d1i, d2i: size of the input matrix 1352 ! inmatrix: input matrix with the values to fill the output matrix 1353 ! ind: dimension of the input matrix that the list of indices refer to 1354 ! dlist: number of indices from the list 1355 ! inlist: list of indices from the input matrix 1356 ! olist: list of indices from the output matrix 1357 ! missval: missing value 1358 ! od: dimension of the output matix to which assign the indices of the list 1359 ! d1o, d2o: size of the output matrix 1360 ! omat: output matrix 1361 1362 fname = 'fill_matrix2DRK_winmat2D_list1D' 1363 1364 omat = missval 1365 1366 IF (ind == 1) THEN 1367 isame = d2i 1368 irun = d1i 1369 ELSE 1370 isame = d1i 1371 irun = d2i 1372 END IF 1373 1374 IF (od == 1) THEN 1375 osame = d2o 1376 orun = d1o 1377 ELSE 1378 osame = d1o 1379 orun = d2o 1380 END IF 1381 1382 IF (isame /= osame) THEN 1383 WRITE(isS,'(I3)')isame 1384 WRITE(osS,'(I3)')osame 1385 msg = 'Resultant working size from input ' // isS // ' to output ' // osS // ' differ !!' 1386 CALL ErrMsg(msg, fname, -1) 1387 END IF 1388 1389 ilx = MAXVAL(inlist) 1390 olx = MAXVAL(olist) 1391 1392 IF (ilx > irun) THEN 1393 WRITE(isS,'(I3)')ilx 1394 WRITE(osS,'(I3)')irun 1395 msg = 'Maximum value in input indices ' // isS // ' larger than assigned dimension ' // osS // & 1396 ' !!' 1397 CALL ErrMsg(msg, fname, -1) 1398 END IF 1399 1400 IF (olx > orun) THEN 1401 WRITE(isS,'(I3)')olx 1402 WRITE(osS,'(I3)')orun 1403 msg = 'Maximum value in output indices ' // isS // ' larger than assigned dimension ' // osS // & 1404 ' !!' 1405 CALL ErrMsg(msg, fname, -1) 1406 END IF 1407 1408 IF (od == 1) THEN 1409 IF (ind == 1) THEN 1410 DO il=1, dlist 1411 omat(olist(il),:) = inmatrix(inlist(il),:) 1412 END DO 1413 ELSE 1414 DO il=1, dlist 1415 omat(olist(il),:) = inmatrix(:,inlist(il)) 1416 END DO 1417 END IF 1418 ELSE 1419 IF (ind == 1) THEN 1420 DO il=1, dlist 1421 omat(:,olist(il)) = inmatrix(inlist(il),:) 1422 END DO 1423 ELSE 1424 DO il=1, dlist 1425 omat(:,olist(il)) = inmatrix(:,inlist(il)) 1426 END DO 1427 END IF 1428 END IF 1429 1430 RETURN 1431 1432 END SUBROUTINE fill_matrix2DRK_winmat2D_list1D 1433 1434 1231 1435 END MODULE module_generic
Note: See TracChangeset
for help on using the changeset viewer.