1
- ! MD5 of template: 712f522020dbe2eab390eba5980d46a1
1
+ ! MD5 of template: 0b9f273f3eb8d1227efa1e89e6732368
2
2
! Array related routines (Integration, Interpolation, etc.)
3
3
! Thomas Robitaille (c) 2009
4
4
@@ -41,6 +41,14 @@ module lib_array
41
41
module procedure integral_subset_dp
42
42
end interface integral
43
43
44
+ public :: cumulative_integral
45
+ interface cumulative_integral
46
+ module procedure cumulative_integral_sp
47
+ module procedure cumulative_integral_dp
48
+ ! module procedure cumulative_integral_subset_sp
49
+ ! module procedure cumulative_integral_subset_dp
50
+ end interface cumulative_integral
51
+
44
52
public :: integral_linlog
45
53
interface integral_linlog
46
54
module procedure integral_linlog_sp
@@ -49,6 +57,14 @@ module lib_array
49
57
module procedure integral_linlog_subset_dp
50
58
end interface integral_linlog
51
59
60
+ public :: cumulative_integral_linlog
61
+ interface cumulative_integral_linlog
62
+ module procedure cumulative_integral_linlog_sp
63
+ module procedure cumulative_integral_linlog_dp
64
+ ! module procedure cumulative_integral_linlog_subset_sp
65
+ ! module procedure cumulative_integral_linlog_subset_dp
66
+ end interface cumulative_integral_linlog
67
+
52
68
public :: integral_loglin
53
69
interface integral_loglin
54
70
module procedure integral_loglin_sp
@@ -57,6 +73,14 @@ module lib_array
57
73
module procedure integral_loglin_subset_dp
58
74
end interface integral_loglin
59
75
76
+ public :: cumulative_integral_loglin
77
+ interface cumulative_integral_loglin
78
+ module procedure cumulative_integral_loglin_sp
79
+ module procedure cumulative_integral_loglin_dp
80
+ ! module procedure cumulative_integral_loglin_subset_sp
81
+ ! module procedure cumulative_integral_loglin_subset_dp
82
+ end interface cumulative_integral_loglin
83
+
60
84
public :: integral_loglog
61
85
interface integral_loglog
62
86
module procedure integral_loglog_sp
@@ -65,6 +89,14 @@ module lib_array
65
89
module procedure integral_loglog_subset_dp
66
90
end interface integral_loglog
67
91
92
+ public :: cumulative_integral_loglog
93
+ interface cumulative_integral_loglog
94
+ module procedure cumulative_integral_loglog_sp
95
+ module procedure cumulative_integral_loglog_dp
96
+ ! module procedure cumulative_integral_loglog_subset_sp
97
+ ! module procedure cumulative_integral_loglog_subset_dp
98
+ end interface cumulative_integral_loglog
99
+
68
100
public :: locate
69
101
interface locate
70
102
module procedure locate_sp
@@ -317,6 +349,41 @@ real(dp) function integral_loglog_subset_dp(x,y,x1,x2)
317
349
integral_loglog_subset_dp = integral_general_subset_dp(x, y, x1, x2, interp1d_loglog_dp, trapezium_loglog_dp)
318
350
end function integral_loglog_subset_dp
319
351
352
+ function cumulative_integral_dp (x ,y )
353
+ ! Total cumulative_integral of a function
354
+ implicit none
355
+ real (dp),intent (in ) :: x(:),y(:)
356
+ real (dp), dimension (size (y)) :: cumulative_integral_dp
357
+ cumulative_integral_dp = cumulative_integral_general_dp(x, y, trapezium_dp)
358
+ end function cumulative_integral_dp
359
+
360
+ function cumulative_integral_linlog_dp (x ,y )
361
+ ! Total cumulative_integral of a function
362
+ ! (uses linlog interpolation)
363
+ implicit none
364
+ real (dp),intent (in ) :: x(:),y(:)
365
+ real (dp), dimension (size (y)) :: cumulative_integral_linlog_dp
366
+ cumulative_integral_linlog_dp = cumulative_integral_general_dp(x, y, trapezium_linlog_dp)
367
+ end function cumulative_integral_linlog_dp
368
+
369
+ function cumulative_integral_loglin_dp (x ,y )
370
+ ! Total cumulative_integral of a function
371
+ ! (uses loglin interpolation)
372
+ implicit none
373
+ real (dp),intent (in ) :: x(:),y(:)
374
+ real (dp), dimension (size (y)) :: cumulative_integral_loglin_dp
375
+ cumulative_integral_loglin_dp = cumulative_integral_general_dp(x, y, trapezium_loglin_dp)
376
+ end function cumulative_integral_loglin_dp
377
+
378
+ function cumulative_integral_loglog_dp (x ,y )
379
+ ! Total cumulative_integral of a function
380
+ ! (uses log10 interpolation)
381
+ implicit none
382
+ real (dp),intent (in ) :: x(:),y(:)
383
+ real (dp), dimension (size (y)) :: cumulative_integral_loglog_dp
384
+ cumulative_integral_loglog_dp = cumulative_integral_general_dp(x, y, trapezium_loglog_dp)
385
+ end function cumulative_integral_loglog_dp
386
+
320
387
real(dp) function integral_general_dp (x ,y ,f_chunk ) result(sum)
321
388
! Total integral of a function
322
389
implicit none
@@ -335,6 +402,25 @@ end function f_chunk
335
402
end do
336
403
end function integral_general_dp
337
404
405
+ function cumulative_integral_general_dp (x ,y ,f_chunk ) result(c)
406
+ ! Total integral of a function
407
+ implicit none
408
+ real (dp),intent (in ) :: x(:),y(:)
409
+ integer :: j
410
+ interface
411
+ real(dp) function f_chunk (x1 ,y1 ,x2 ,y2 )
412
+ import :: dp
413
+ implicit none
414
+ real (dp),intent (in ) :: x1,y1,x2,y2
415
+ end function f_chunk
416
+ end interface
417
+ real (dp), dimension (size (y)) :: c
418
+ c(1 ) = 0._dp
419
+ do j= 1 ,size (x)- 1
420
+ c(j+1 )= c(j)+ f_chunk(x(j),y(j),x(j+1 ),y(j+1 ))
421
+ end do
422
+ end function cumulative_integral_general_dp
423
+
338
424
real(dp) function integral_general_subset_dp (x ,y ,x1 ,x2 ,f_interp ,f_chunk ) result(sum)
339
425
! Integral of a function between two limits
340
426
@@ -371,7 +457,7 @@ end function f_chunk
371
457
if (x1.gt. x(1 )) then
372
458
i1 = locate(x,x1)
373
459
f1 = f_interp(x,y,x1)
374
- else
460
+ else
375
461
i1 = 0
376
462
f1 = 0._dp
377
463
end if
@@ -1269,6 +1355,41 @@ real(sp) function integral_loglog_subset_sp(x,y,x1,x2)
1269
1355
integral_loglog_subset_sp = integral_general_subset_sp(x, y, x1, x2, interp1d_loglog_sp, trapezium_loglog_sp)
1270
1356
end function integral_loglog_subset_sp
1271
1357
1358
+ function cumulative_integral_sp (x ,y )
1359
+ ! Total cumulative_integral of a function
1360
+ implicit none
1361
+ real (sp),intent (in ) :: x(:),y(:)
1362
+ real (sp), dimension (size (y)) :: cumulative_integral_sp
1363
+ cumulative_integral_sp = cumulative_integral_general_sp(x, y, trapezium_sp)
1364
+ end function cumulative_integral_sp
1365
+
1366
+ function cumulative_integral_linlog_sp (x ,y )
1367
+ ! Total cumulative_integral of a function
1368
+ ! (uses linlog interpolation)
1369
+ implicit none
1370
+ real (sp),intent (in ) :: x(:),y(:)
1371
+ real (sp), dimension (size (y)) :: cumulative_integral_linlog_sp
1372
+ cumulative_integral_linlog_sp = cumulative_integral_general_sp(x, y, trapezium_linlog_sp)
1373
+ end function cumulative_integral_linlog_sp
1374
+
1375
+ function cumulative_integral_loglin_sp (x ,y )
1376
+ ! Total cumulative_integral of a function
1377
+ ! (uses loglin interpolation)
1378
+ implicit none
1379
+ real (sp),intent (in ) :: x(:),y(:)
1380
+ real (sp), dimension (size (y)) :: cumulative_integral_loglin_sp
1381
+ cumulative_integral_loglin_sp = cumulative_integral_general_sp(x, y, trapezium_loglin_sp)
1382
+ end function cumulative_integral_loglin_sp
1383
+
1384
+ function cumulative_integral_loglog_sp (x ,y )
1385
+ ! Total cumulative_integral of a function
1386
+ ! (uses log10 interpolation)
1387
+ implicit none
1388
+ real (sp),intent (in ) :: x(:),y(:)
1389
+ real (sp), dimension (size (y)) :: cumulative_integral_loglog_sp
1390
+ cumulative_integral_loglog_sp = cumulative_integral_general_sp(x, y, trapezium_loglog_sp)
1391
+ end function cumulative_integral_loglog_sp
1392
+
1272
1393
real(sp) function integral_general_sp (x ,y ,f_chunk ) result(sum)
1273
1394
! Total integral of a function
1274
1395
implicit none
@@ -1287,6 +1408,25 @@ end function f_chunk
1287
1408
end do
1288
1409
end function integral_general_sp
1289
1410
1411
+ function cumulative_integral_general_sp (x ,y ,f_chunk ) result(c)
1412
+ ! Total integral of a function
1413
+ implicit none
1414
+ real (sp),intent (in ) :: x(:),y(:)
1415
+ integer :: j
1416
+ interface
1417
+ real(sp) function f_chunk (x1 ,y1 ,x2 ,y2 )
1418
+ import :: sp
1419
+ implicit none
1420
+ real (sp),intent (in ) :: x1,y1,x2,y2
1421
+ end function f_chunk
1422
+ end interface
1423
+ real (sp), dimension (size (y)) :: c
1424
+ c(1 ) = 0._sp
1425
+ do j= 1 ,size (x)- 1
1426
+ c(j+1 )= c(j)+ f_chunk(x(j),y(j),x(j+1 ),y(j+1 ))
1427
+ end do
1428
+ end function cumulative_integral_general_sp
1429
+
1290
1430
real(sp) function integral_general_subset_sp (x ,y ,x1 ,x2 ,f_interp ,f_chunk ) result(sum)
1291
1431
! Integral of a function between two limits
1292
1432
@@ -1323,7 +1463,7 @@ end function f_chunk
1323
1463
if (x1.gt. x(1 )) then
1324
1464
i1 = locate(x,x1)
1325
1465
f1 = f_interp(x,y,x1)
1326
- else
1466
+ else
1327
1467
i1 = 0
1328
1468
f1 = 0._sp
1329
1469
end if
0 commit comments