-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_f_udunits_2.F90
198 lines (181 loc) · 8.89 KB
/
test_f_udunits_2.F90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
program test_f_udunits_2 ! very rudimentary test program for libudunits2 Fortran nterface
!
! example of compilation and execution with gfortran (udunits2 installed in /opt/udunits2)
! test program in fortran_udunits2/tests, source code in fortran_udunits2/source
! gfortran -Wall -Wno-tabs -I/opt/udunits2/include test_f_udunits_2.F90 -I../source -L/opt/udunits2/lib -ludunits2 -lexpat
! LD_LIBRARY_PATH=/opt/udunits2/lib ./a.out
!
use f_udunits_2
implicit none
type(UT_SYSTEM_PTR) :: sys
type(CV_CONVERTER_PTR) :: conv1, conv2, conv3, time_cvt, time_cvt0
type(UT_UNIT_PTR) :: unit1, unit2, unit3, unit4, unit5
type(UT_UNIT_PTR) :: unit0, unit6, unit7, unit8, unit9, unit06
type(UT_UNIT_PTR) :: erg, watt, watt_s, sec, time_base, sec0, time_base0
character(len=*), parameter :: machin1 = "km/hour"
character(len=*), parameter :: machin2 = "m/second"
character(len=*), parameter :: machin3 = "2 knots"
character(len=*), parameter :: machin4 = "watt"
character(len=*), parameter :: machin5 = "radian"
character(len=128) :: buffer
real*8, parameter :: ONE = 1.01
real*8, parameter :: TWO = 2.0
real*8, parameter :: THREE = 3.03
real*8, parameter :: FOUR = 4.04
real*8, parameter :: TEN = 10.0
real*8, parameter :: ZERO = 0.0
real :: A, B
integer :: junk
integer :: charset
integer hour, minute, year, month, day
real(C_DOUBLE) :: second, time, resolution
charset = UT_ASCII
sys = f_ut_read_xml("")
year = -2000; month = 8; day = 8; hour = 15; minute = 45; second = 15.55; resolution = 0.0
time = f_ut_encode_time(year, month, day, hour, minute, second)
print *, "TIME=", time, " =<", year, month, day, hour, minute, real(second)
year = 0; month = 0; day = 0; hour = 0; minute = 0; second = 0.0; resolution = -999.999
call f_ut_decode_time(time, year, month, day, hour, minute, second, resolution)
print *, "TIME=", time, " =>", year, month, day, hour, minute, real(second), " +-", real(resolution)
sec0 = f_ut_parse(sys, "second", charset)
time_base = f_ut_offset_by_time(sec0, f_ut_encode_time(2012, 08, 08, 15, 00, ZERO))
time_base0 = f_ut_offset_by_time(sec0, f_ut_encode_time(2001, 01, 01, 00, 00, ZERO))
time_cvt = f_ut_get_converter(sec0, time_base)
if (.not. c_associated(time_cvt%ptr)) print *, 'ERROR in time_cvt'
time_cvt0 = f_ut_get_converter(sec0, time_base0)
if (.not. c_associated(time_cvt0%ptr)) print *, 'ERROR in time_cvt0'
junk = f_ut_format(time_base, buffer, UT_NAMES)
print *, "DEBUG: new unit of time_base='", trim(buffer), "'"
print *, "converted time =", f_cv_convert_double(time_cvt, time)
junk = f_ut_format(time_base0, buffer, UT_NAMES)
print *, "DEBUG: new unit of time_base='", trim(buffer), "'"
print *, "converted time =", f_cv_convert_double(time_cvt0, time)
unit1 = f_ut_parse(sys, machin1, charset)
if (.not. c_associated(unit1%ptr)) print *, 'ERROR in unit1'
junk = f_ut_format(unit1, buffer, UT_NAMES)
print *, "DEBUG: unit UT_NAMES of ", machin1, "='", trim(buffer), "'"
junk = f_ut_format(unit1, buffer, UT_DEFINITION)
print *, "DEBUG: unit UT_DEFINITION of ", machin1, "='", trim(buffer), "'"
unit2 = f_ut_parse(sys, machin2, charset)
if (.not. c_associated(unit2%ptr)) print *, 'ERROR in unit2'
junk = f_ut_format(unit2, buffer, UT_NAMES)
print *, "DEBUG: unit UT_NAMES of ", machin2, "='", trim(buffer), "'"
junk = f_ut_format(unit2, buffer, UT_DEFINITION)
print *, "DEBUG: unit UT_DEFINITION of ", machin2, "='", trim(buffer), "'"
conv1 = f_ut_get_converter(unit1, unit2) ! machin2 to machin1
if (f_ut_are_convertible(unit1, unit2)) print *, machin1, " can be converted into ", machin2
if (.not. c_associated(conv1%ptr)) print *, 'ERROR in conv1'
a = 1.5
B = f_cv_convert_float(conv1, A)
print *, a, machin1, ' is the same as', b, machin2
unit3 = f_ut_parse(sys, machin3, charset)
if (.not. c_associated(unit3%ptr)) print *, 'ERROR in unit3'
junk = f_ut_format(unit3, buffer, UT_NAMES)
print *, "DEBUG: unit UT_NAMES of ", machin3, "='", trim(buffer), "'"
junk = f_ut_format(unit3, buffer, UT_DEFINITION)
print *, "DEBUG: unit UT_DEFINITION of ", machin3, "='", trim(buffer), "'"
conv2 = f_ut_get_converter(unit3, unit1) ! machin3 to machin1
if (f_ut_are_convertible(unit3, unit1)) print *, machin3, " can be converted into ", machin1
if (.not. c_associated(conv2%ptr)) print *, 'ERROR in conv2'
a = 1.5
B = f_cv_convert_float(conv2, A)
print *, a, machin3, ' is the same as', b, machin1
conv3 = f_ut_get_converter(unit3, unit2) ! machin3 to machin2
if (f_ut_are_convertible(unit3, unit2)) print *, machin3, " can be converted into ", machin2
if (.not. c_associated(conv3%ptr)) print *, 'ERROR in conv3'
a = 1.5
B = f_cv_convert_float(conv3, A)
print *, a, machin3, ' is the same as', b, machin2
print *, "COMPARE ", machin1, " with ", machin1, " = ", f_ut_compare(unit1, unit1), &
", same system =", f_ut_same_system(unit1, unit1)
print *, "COMPARE ", machin1, " with ", machin2, " = ", f_ut_compare(unit1, unit2), &
", same system =", f_ut_same_system(unit1, unit2)
print *, "COMPARE ", machin1, " with ", machin3, " = ", f_ut_compare(unit1, unit3), &
", same system =", f_ut_same_system(unit1, unit3)
print *, "COMPARE ", machin2, " with ", machin3, " = ", f_ut_compare(unit2, unit3), &
", same system =", f_ut_same_system(unit2, unit3)
unit4 = f_ut_parse(sys, machin4, charset)
if (.not. c_associated(unit4%ptr)) print *, 'ERROR in unit4'
if (.not. f_ut_are_convertible(unit3, unit4)) print *, machin3, " cannot be converted into ", machin4, &
", same system =", f_ut_same_system(unit3, unit4)
print *, machin4, " is dimensionless =", f_ut_is_dimensionless(unit4)
unit5 = f_ut_parse(sys, machin5, charset)
if (.not. c_associated(unit5%ptr)) print *, 'ERROR in unit5'
print *, machin5, " is dimensionless =", f_ut_is_dimensionless(unit5)
junk = f_ut_format(unit4, buffer, UT_NAMES)
print *, "DEBUG: unit ='", trim(buffer), "'"
junk = f_ut_format(unit5, buffer, UT_NAMES)
print *, "DEBUG: unit ='", trim(buffer), "'"
unit6 = f_ut_divide(unit4, unit5)
print *, "DIVIDE ", machin4, " by ", machin5
junk = f_ut_format(unit6, buffer, UT_NAMES)
print *, "DEBUG: new unit = '", trim(buffer), "'"
print *, "MULTIPLY by ", machin5
unit06 = f_ut_multiply(unit6, unit5)
junk = f_ut_format(unit06, buffer, UT_NAMES)
print *, "DEBUG: new unit = '", trim(buffer), "'"
print *, "SCALE by", THREE
unit7 = f_ut_scale(THREE, unit06)
junk = f_ut_format(unit7, buffer, UT_NAMES)
print *, "DEBUG: new unit = '", trim(buffer), "'"
print *, "OFFSET by", FOUR
unit8 = f_ut_offset(unit7, FOUR)
junk = f_ut_format(unit8, buffer, UT_NAMES)
print *, "DEBUG: new unit = '", trim(buffer), "'"
junk = f_ut_format(unit7, buffer, UT_NAMES)
print *, "RAISE 3 ", trim(buffer)
unit9 = f_ut_raise(unit7, 3)
junk = f_ut_format(unit9, buffer, UT_NAMES)
print *, "DEBUG: new unit = '", trim(buffer), "'"
print *, "INVERT"
unit0 = f_ut_invert(unit9)
junk = f_ut_format(unit0, buffer, UT_NAMES)
print *, "DEBUG: new unit = '", trim(buffer), "'"
call f_ut_free(unit0)
print *, "root 2"
unit0 = f_ut_root(unit9, 2)
print *, "LOG", TWO
unit0 = f_ut_log(TWO, unit9)
junk = f_ut_format(unit0, buffer, UT_NAMES)
print *, "DEBUG: new unit = '", trim(buffer), "'"
call f_ut_free(unit0)
print *, "LOG", TEN
unit0 = f_ut_log(TEN, unit9)
junk = f_ut_format(unit0, buffer, UT_NAMES)
print *, "DEBUG: new unit = '", trim(buffer), "'"
call f_ut_free(unit0)
print *, "LOG", FOUR
unit0 = f_ut_log(FOUR, unit9)
junk = f_ut_format(unit0, buffer, UT_NAMES)
print *, "DEBUG: new unit = '", trim(buffer), "'"
call f_ut_free(unit0)
print *, "root 3"
unit0 = f_ut_root(unit9, 3)
junk = f_ut_format(unit0, buffer, UT_NAMES)
print *, "DEBUG: new unit = '", trim(buffer), "'"
watt = f_ut_parse(sys, "watt", charset)
sec = f_ut_parse(sys, "second", charset)
erg = f_ut_parse(sys, "erg", charset)
watt_s = f_ut_multiply(watt, sec)
junk = f_ut_format(watt_s, buffer, UT_NAMES)
print *, "DEBUG: watt_s = '", trim(buffer), "'"
junk = f_ut_format(erg, buffer, UT_NAMES)
print *, "DEBUG: erg = '", trim(buffer), "'"
if (f_ut_are_convertible(watt_s, erg)) print *, "watt.s can be converted into erg"
print *, 'UNIT4 name is ', trim(f_ut_get_name(unit4, UT_ASCII))
print *, 'UNIT4 symbol is ', trim(f_ut_get_symbol(unit4, UT_ASCII))
print *, 'UNIT5 name is ', trim(f_ut_get_name(unit5, UT_ASCII))
print *, 'UNIT5 symbol is ', trim(f_ut_get_symbol(unit5, UT_ASCII))
print *, 'sec name is ', trim(f_ut_get_name(sec, UT_ASCII))
print *, 'sec symbol is ', trim(f_ut_get_symbol(sec, UT_ASCII))
call f_ut_free(unit1)
call f_ut_free(unit2)
call f_ut_free(unit3)
call f_ut_free(unit4)
call f_cv_free(conv1)
call f_cv_free(conv2)
call f_cv_free(conv3)
call f_ut_free_system(sys)
!
stop
end