[go: up one dir, main page]

File: udunits2lib.texi

package info (click to toggle)
udunits 2.1.23-3
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 4,024 kB
  • sloc: ansic: 21,710; sh: 9,512; xml: 2,129; yacc: 458; makefile: 391; lex: 260
file content (1743 lines) | stat: -rw-r--r-- 63,230 bytes parent folder | download
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
\input texinfo  @c -*-texinfo-*-
@c %**start of header
@setfilename udunits2lib.info
@settitle The UDUNITS-2 C API Guide
@c %**end of header
@dircategory Software libraries
@direntry
* UDUNITS-2: (udunits2lib).     The Unidata units library.
@end direntry
@syncodeindex fn cp
@syncodeindex tp cp
@copying
@include LICENSE
@end copying

@titlepage
@title The UDUNITS-2 C API
@author Steven R. Emmerson

@page
@vskip 0pt plus 1filll
@insertcopying
@end titlepage

@contents

@ifnottex
@node Top, Synopsis, (dir), (dir)
@top UDUNITS-2
This manual describes how to use the C API of the UDUNITS-2 library.
Among other things, the library allows C code to obtain a binary
representation of a unit of a physical quantity, to
operate on such units, and to convert numeric values between compatible
units.

The library comes with an extensive database of units all referenced to the
SI system of units.

@insertcopying
@end ifnottex

@menu
* Synopsis::            Terse usage display
* Why::                 What's a unit package good for?
* Unit-Systems::        Explanation of unit-systems and how to get one
* Parsing::             Converting strings into units
* Syntax::              Syntax for string representation of units
* Formatting::          Converting units into strings
* Value Conversion::    Converting values between units
* Prefixes::            Defining unit prefixes
* Mapping::             Mapping between units and identifiers
* Operations::          Operations on units
* Time::                Handling time
* Errors::              Error-handling
* Database::            The units database
* Types::               Data types
* Complete Index::      Complete index
@end menu

@node Synopsis, Why, Top, Top
@chapter Synopsis
@cindex synopsis

Coding:
@example
#include <udunits2.h>
@quotation
@multitable {ut_error_message_handler} {ut_get_dimensionless_unit_one(}
@item ut_system* @tab ut_read_xml(const char* @var{path});
@item ut_system* @tab ut_new_system(void);
@item void      @tab ut_free_system(ut_system* @var{system});
@item ut_system* @tab ut_get_system(const ut_unit* @var{unit});
@item ut_unit*   @tab ut_get_dimensionless_unit_one(const ut_system* @var{system});
@item ut_unit*   @tab ut_get_unit_by_name(const ut_system* @var{system}, const char* @var{name});
@item ut_unit*   @tab ut_get_unit_by_symbol(const ut_system* @var{system}, const char* @var{symbol});
@item ut_status @tab  ut_set_second(const ut_unit* @var{second});
@item ut_status @tab  ut_add_name_prefix(ut_system* @var{system}, const char* @var{name}, double @var{value});
@item ut_status @tab  ut_add_symbol_prefix(ut_system* @var{system}, const char* @var{symbol}, double @var{value});
@item ut_unit*   @tab ut_new_base_unit(ut_system* @var{system});
@item ut_unit*   @tab ut_new_dimensionless_unit(ut_system* @var{system});
@item ut_unit*   @tab ut_clone(const ut_unit* @var{unit});
@item void      @tab ut_free(ut_unit* @var{unit});
@item const char* @tab ut_get_name(const ut_unit* @var{unit}, ut_encoding @var{encoding});
@item ut_status @tab ut_map_name_to_unit(const char* @var{name}, const ut_encoding @var{encoding}, const ut_unit* @var{unit});
@item ut_status @tab ut_unmap_name_to_unit(ut_system* @var{system}, const char* @var{name}, const ut_encoding @var{encoding});
@item ut_status @tab ut_map_unit_to_name(const ut_unit* @var{unit}, const char* @var{name}, ut_encoding @var{encoding});
@item ut_status @tab ut_unmap_unit_to_name(const ut_unit* @var{unit}, ut_encoding @var{encoding});
@item const char* @tab ut_get_symbol(const ut_unit* @var{unit}, ut_encoding @var{encoding});
@item ut_status @tab ut_map_symbol_to_unit(const char* @var{symbol}, const ut_encoding @var{encoding}, const ut_unit* @var{unit});
@item ut_status @tab ut_unmap_symbol_to_unit(ut_system* @var{system}, const char* @var{symbol}, const ut_encoding @var{encoding});
@item ut_status @tab ut_map_unit_to_symbol(const ut_unit* @var{unit}, const char* @var{symbol}, ut_encoding @var{encoding});
@item ut_status @tab ut_unmap_unit_to_symbol(const ut_unit* @var{unit}, ut_encoding @var{encoding});
@item int @tab ut_is_dimensionless(const ut_unit* @var{unit});
@item int @tab ut_same_system(const ut_unit* @var{unit1}, const ut_unit* @var{unit2});
@item int @tab ut_compare(const ut_unit* @var{unit1}, const ut_unit* @var{unit2});
@item int @tab ut_are_convertible(const ut_unit* @var{unit1}, const ut_unit* @var{unit2});
@item cv_converter* @tab ut_get_converter(ut_unit* @var{from}, ut_unit* @var{to});
@item ut_unit* @tab ut_scale(double @var{factor}, const ut_unit* @var{unit});
@item ut_unit* @tab ut_offset(const ut_unit* @var{unit}, double @var{offset});
@item ut_unit* @tab ut_offset_by_time(const ut_unit* @var{unit}, double @var{origin});
@item ut_unit* @tab ut_multiply(const ut_unit* @var{unit1}, const ut_unit* @var{unit2});
@item ut_unit* @tab ut_invert(const ut_unit* @var{unit});
@item ut_unit* @tab ut_divide(const ut_unit* @var{numer}, const ut_unit* @var{denom});
@item ut_unit* @tab ut_raise(const ut_unit* @var{unit}, int @var{power});
@item ut_unit* @tab ut_root(const ut_unit* @var{unit}, int @var{root});
@item ut_unit* @tab ut_log(double @var{base}, const ut_unit* @var{reference});
@item ut_unit* @tab ut_parse(const ut_system* @var{system}, const char* @var{string}, ut_encoding @var{encoding});
@item char*   @tab ut_trim(char* @var{string}, ut_encoding @var{encoding});
@item int @tab ut_format(const ut_unit* @var{unit}, char* @var{buf}, size_t @var{size}, unsigned @var{opts});
@item ut_status @tab ut_accept_visitor(const ut_unit* @var{unit}, const ut_visitor* @var{visitor}, void* @var{arg});
@item double @tab ut_encode_date(int @var{year}, int @var{month}, int @var{day});
@item double @tab ut_encode_clock(int @var{hours}, int @var{minutes}, double @var{seconds});
@item double @tab ut_encode_time(int @var{year}, int @var{month}, int @var{day}, int @var{hour}, int @var{minute}, double @var{second});
@item void @tab ut_decode_time(double @var{value}, int* @var{year}, int* @var{month}, int* @var{day}, int* @var{hour}, int* @var{minute}, double* @var{second}, double* @var{resolution});
@item ut_status @tab ut_get_status(void);
@item void @tab ut_set_status(ut_status @var{status});
@item int @tab ut_handle_error_message(const char* @var{fmt}, ...);
@item ut_error_message_handler@tab ut_set_error_message_handler(ut_error_message_handler @var{handler});
@item int @tab ut_write_to_stderr(const char* @var{fmt}, va_list @var{args});
@item int @tab ut_ignore(const char* @var{fmt}, va_list @var{args});
@item 
@item float @tab cv_convert_float(const cv_converter* @var{converter}, float @var{value});
@item double @tab cv_convert_double(const cv_converter* @var{converter}, double @var{value});
@item float* @tab cv_convert_floats(const cv_converter* @var{converter}, const float* @var{in}, size_t @var{count}, float* @var{out});
@item double* @tab cv_convert_doubles(const cv_converter* @var{converter}, const double* @var{const} in, @var{size_t} count, @var{double}* out);
@item void @tab cv_free(cv_converter* @var{conv});
@end multitable
@end quotation
@end example

Compiling:
@example
c89 -I @emph{includedir} ...
@end example

Where @emph{includedir} is the installation-directory for C header
files (e.g., @code{/usr/local/include}).

Linking:
@example
c89 ... -L@emph{libdir} -ludunits2 -lexpat ... -lm
@end example

Where @emph{libdir} is the installation-directory for object code
libraries (e.g., @code{/usr/local/lib}).

@node Why, Unit-Systems, Synopsis, Top
@chapter What's a Unit Package Good For?

The existance of a software package is justified by what you can do with it.
The three main things you can do with the UDUNIT-2 package are
@enumerate
@item
@ref{Value Conversion,
Convert numeric values between compatible units}.
@item
Convert a string representation of a unit into a binary one --- enabling
the programatic manipulation of units.
There are three ways to do this:
@itemize
@item
@ref{Extracting,Get the unit} from a @ref{unit-system}.
This requires that
you know the unit's name or symbol and that the unit is in a unit-system.  
@item
@ref{Parsing,Parse a string representation of the unit into its binary
representation}.
This requires that the string be parsable by @code{@ref{ut_parse()}}.
@item
@ref{Operations,Explicity construct the unit from subcomponent units
using unit operations}.
@end itemize
@item
@ref{Formatting,Convert a binary representation of a unit into a string} ---
enabling the printing and storing of units in a human-readable form.
@end enumerate
While the above might seem to be trivial activities, their 
general availability at the time might have helped prevent
the @uref{http://en.wikipedia.org/wiki/Mars_Climate_Orbiter,
Mars Climate Orbiter} fiasco.

@anchor{unit-system}
@node Unit-Systems, Value Conversion, Why, Top
@chapter Unit-Systems
@cindex unit-system
@cindex system of units

A unit-system is a set of units that are all defined in terms of the same
set of
@cindex unit, base
@cindex base unit
base units.
In the SI system of units, for example, the base units are the
meter, kilogram, second, ampere, kelvin, mole, and candela.
(For definitions of these base units, see
@uref{http://@/physics.nist.gov/@/cuu/@/Units/@/current.html}.)

In the UDUNITS-2 package, every accessible unit belongs to one and only one
unit-system.  It is not possible to convert numeric values between units
of different unit-systems.  Similarly, units belonging to different
unit-systems always compare unequal.

There are several categories of operations on unit-systems:

@menu
* Obtaining::   How to obtain a unit-system.
* Extracting::  Getting a unit from a unit-system.
* Adding::      Adding new units to a unit-system.
* Prefixes::    Add new unit-prefixes to a unit-system.
* Misc::        Miscelaneous unit-system operations.
@end menu

@node Obtaining, Extracting, , Unit-Systems
@section Obtaining a Unit-System
@cindex database, unit, obtaining predefined
@cindex unit database, obtaining predefined
@cindex unit-system, obtaining predefined
@cindex units, obtaining predefined
@cindex @code{ut_read_xml()}, discussion of
Typically, you would obtain a unit-system of predefined units by reading
the default unit database using @code{@ref{ut_read_xml()}}
with a @code{NULL} pathname argument.
If this doesn't quite match your needs, then there are alternatives.
Together with the typical solution, the means for obtaining a useful
unit-system are (in order of increasing difficulty):

@itemize @bullet
@item
Obtain the default unit-system using @code{@ref{ut_read_xml(),ut_read_xml}(NULL)}.
@item
Copy and customize the unit database and then
call @code{@ref{ut_read_xml()}} with the pathname of the customized
database to obtain a customized unit-system.
@item
Same as either of the above but then adding new units to the unit-system using
@code{@ref{ut_new_base_unit()}} and
@code{@ref{ut_new_dimensionless_unit()}}.
@item
Same as the above but also deriving new units using
@ref{Operations, unit operations}
and then adding them to the unit-system using
@ref{Mapping, unit mapping}.
@item
Same as the above but starting with an empty unit-system obtained from
@code{@ref{ut_new_system()}},
in which case you will definitely have to start with
@code{@ref{ut_new_base_unit()}} and
@code{@ref{ut_new_dimensionless_unit()}}.
@end itemize

You should pass every unit-system pointer to @code{@ref{ut_free_system()}}
when you no longer need the corresponding unit-system.

@anchor{ut_read_xml()}
@deftypefun @code{ut_system*} ut_read_xml @code{(const char* @var{path})}
Reads the XML-formatted unit-database specified by @var{path}
and returns the corresponding unit-sytem.
If @var{path} is @code{NULL}, then the pathname specified by the
environment variable @code{UDUNITS2_XML_PATH} is used if set; otherwise,
the compile-time pathname of the installed, default, unit database is
used.
You should pass the returned pointer to @code{ut_free_system()} when you
no longer need the unit-system.
If an error occurs,
then this function writes an error-message using
@code{@ref{ut_handle_error_message()}}
and returns @code{NULL}.
Also, @code{@ref{ut_get_status()}} will return one of the following:

@table @code
@item UT_OPEN_ARG
@var{path} is non-@code{NULL} but the file couldn't be opened.
See @code{errno} for the reason.
@item UT_OPEN_ENV
@var{path} is @code{NULL} and environment variable
@code{UDUNITS2_XML_PATH} is set but the file couldn't be opened.
See @code{errno} for the reason.
@item UT_OPEN_DEFAULT
@var{path} is @code{NULL}, environment variable
@code{UDUNITS2_XML_PATH} is unset, and the installed, default, unit
database couldn't be opened.
See @code{errno} for the reason.
@item UT_OS
Operating-system error.  See @code{errno}.
@item UT_PARSE
The database file couldn't be parsed.
@end table
@end deftypefun

@anchor{ut_new_system()}
@deftypefun @code{ut_system*} ut_new_system @code{(void)}
Creates and returns a new unit-system.
On success, the unit-system will be empty
except for the dimensionless unit one.
You should pass the returned pointer to @code{ut_free_system()} when you
no longer need the unit-system.
If an error occurs,
then this function writes an error-message using
@code{@ref{ut_handle_error_message()}}
and returns @code{NULL}.
Also, @code{@ref{ut_get_status()}} will return the following:

@table @code
@item UT_OS
Operating-system error.  See @code{errno}.
@end table
@end deftypefun

@node Extracting, Adding, Obtaining, Unit-Systems
@section Extracting Units from a Unit-System

@strong{NOTE:} This section covers low-level access to the indidual units of a
@ref{unit-system}.
General parsing of arbitrary unit specifications is coverted in
the section @ref{Parsing}.

A @ref{unit-system} contains mappings from identifiers to units (and
vice versa).
Consequently, once you have a unit-system, you can easily
obtain a unit for which you know the name or symbol using
the function @code{@ref{ut_get_unit_by_name()}} or
@code{@ref{ut_get_unit_by_symbol()}}.

@cindex getting a unit by its name
@cindex unit, getting by name
@anchor{ut_get_unit_by_name()}
@deftypefun @code{ut_unit*} ut_get_unit_by_name @code{(const ut_system* @var{system}, const char* @var{name})}
Returns the unit to which @var{name} maps from the unit-system referenced by
@var{system} or @code{NULL} if no such unit exists.
Name comparisons are case-insensitive.
If this function returns @code{NULL}, then
@code{@ref{ut_get_status()}} will return 
one of the following:

@table @code
@item UT_SUCCESS
@var{name} doesn't map to a unit of @var{system}.
@item UT_BAD_ARG
@var{system} or @var{name} is @code{NULL}.
@end table
@end deftypefun

@cindex getting a unit by its symbol
@cindex unit, getting by symbol
@anchor{ut_get_unit_by_symbol()}
@deftypefun @code{ut_unit*} ut_get_unit_by_symbol @code{(const ut_system* @var{system}, const char* @var{symbol})}
Returns the unit to which @var{symbol} maps from the unit-system referenced by
@var{system} or @code{NULL} if no such unit exists.
Symbol comparisons are case-sensitive.
If this function returns @code{NULL}, then
@code{@ref{ut_get_status()}} will return 
one of the following:

@table @code
@item UT_SUCCESS
@var{symbol} doesn't map to a unit of @var{system}.
@item UT_BAD_ARG
@var{system} or @var{symbol} is @code{NULL}.
@end table
@end deftypefun

@anchor{ut_get_dimensionless_unit_one()}
@deftypefun @code{ut_unit*} ut_get_dimensionless_unit_one @code{(const ut_system* @var{system})}
Returns the dimensionless unit one of the unit-system referenced by
@var{system}.
While not necessary, the returned pointer may be passed to @code{ut_free()}
when you no longer need the unit.
If @var{system} is @code{NULL}, then this function writes an error-message 
using @code{@ref{ut_handle_error_message()}}
and returns @code{NULL}.
Also, @code{@ref{ut_get_status()}} will return @code{UT_BAD_ARG}.
@end deftypefun

@node Adding, Prefixes, Extracting, Unit-Systems
@section Adding Units to a Unit-System
@cindex adding units to a unit-system
@cindex unit, adding to a unit-system
@cindex unit-system, adding a unit to

If you use @code{@ref{ut_read_xml()}}, then you should not normally need to
add any new units to a unit-system.

Because you get units via their names or symbols, adding a unit to a
unit-system actually means mapping one or more identifiers (i.e., names
or symbols) to the unit.
Thereafter, you can use @code{@ref{ut_get_unit_by_name()}} and
@code{@ref{ut_get_unit_by_symbol()}} to retrieve the unit.
The mapping of identifiers to units is covered @ref{Mapping,here}.

Having said that, it is possible to create a new base or dimensionless
unit within a unit-system using @code{@ref{ut_new_base_unit()}} or
@code{@ref{ut_new_dimensionless_unit()}}---you'll just also have to map
identifiers to the newly-created unit in order to be able to retrieve
it later by identifier.

@anchor{ut_new_base_unit()}
@deftypefun @code{ut_unit*} ut_new_base_unit @code{(ut_system* @var{system})}
Creates and adds a new base-unit to the unit-system referenced by @var{system}.
This function returns the new base-unit.
You should pass the returned pointer to @code{ut_free()} when you
no longer need the unit.
If an error occurs,
then this function writes an error-message using
@code{@ref{ut_handle_error_message()}}
and returns @code{NULL}.
Also, @code{@ref{ut_get_status()}} will return one of the following:

@table @code
@item UT_BAD_ARG
@var{system} is @code{NULL}.
@item UT_OS
Operating-system failure.  See @code{errno}.
@end table
If you use @code{@ref{ut_read_xml()}}, then you should not normally need to call this
function.
@end deftypefun

@anchor{ut_new_dimensionless_unit()}
@deftypefun @code{ut_unit*} ut_new_dimensionless_unit @code{(ut_system* @var{system})}
Creates and adds a new dimensionless-unit to the unit-system referenced by @var{system}.
This function returns the new dimensionless-unit.
You should pass the returned pointer to @code{ut_free()} when you
no longer need the unit.
If an error occurs,
then this function writes an error-message using
@code{@ref{ut_handle_error_message()}}
and returns @code{NULL}.
Also, @code{@ref{ut_get_status()}} will return one of the following:

@table @code
@item UT_BAD_ARG
@var{system} is @code{NULL}.
@item UT_OS
Operating-system failure.  See @code{errno}.
@end table
If you use @code{@ref{ut_read_xml()}}, then you should not normally need to call this
function.
@end deftypefun

@node Prefixes, Misc, Adding, Unit-Systems
@section Adding Unit-Prefixes to a Unit-System
@cindex prefixes, adding to a unit-system
@cindex adding prefixes to a unit-system
@cindex unit-system, adding prefixes to a

A prefix is a word or symbol that is appended to the beginning of a word or
symbol that represents a unit in order to modify the value of that unit.  For
example, the prefix ``kilo'' in the word ``kiloamperes'' changes the value
from one ampere to one-thousand amperes.

If you use @code{@ref{ut_read_xml()}}, then you should not normally need to
add any new prefixes to a unit-system.

@anchor{ut_add_name_prefix()}
@deftypefun @code{@ref{ut_status}} ut_add_name_prefix @code{(ut_system* @var{system}, const char* @var{name}, double @var{value})}
Adds the name-prefix @var{name} with the value @var{value}
to the unit-system @var{system}.
A name-prefix is something like ``mega'' or ``milli''.
Comparisons between name-prefixes are case-insensitive.
This function returns one of the following:

@table @code
@item UT_SUCCESS
Success.
@item UT_BAD_ARG
@var{system} or @var{name} is @code{NULL}, or @var{value} is @code{0}.
@item UT_EXISTS
@var{name} already maps to a different value.
@item UT_OS
Operating-system failure.  See @code{errno}.
@end table
@end deftypefun

@anchor{ut_add_symbol_prefix()}
@deftypefun @code{@ref{ut_status}} ut_add_symbol_prefix @code{(ut_system* @var{system}, const char* @var{symbol}, double @var{value})}
Adds the symbol-prefix @var{symbol} with the value @var{value}
to the unit-system @var{system}.
A symbol-prefix is something like ``M'' or ``m''.
Comparisons between symbol-prefixes are case-sensitive.
This function returns one of the following:

@table @code
@item UT_SUCCESS
Success.
@item UT_BAD_ARG
@var{system} or @var{symbol} is @code{NULL}, or @var{value} is @code{0}.
@item UT_EXISTS
@var{symbol} already maps to a different value.
@item UT_OS
Operating-system failure.  See @code{errno}.
@end table
@end deftypefun

@node Misc, , Prefixes, Unit-Systems
@section Miscelaneous Operations on Unit-Systems

@anchor{ut_free_system()}
@deftypefun @code{void} ut_free_system @code{(ut_system* @var{system})}
Frees the unit-system referenced by @var{system}.  All unit-to-identifier and
identifier-to-unit mappings are removed.  Use of @code{system} after this
function returns results in undefined behavior.
@end deftypefun

@anchor{ut_set_second()}
@deftypefun @code{@ref{ut_status}} ut_set_second @code{(const ut_unit* @var{second})}
Sets the ``second'' unit of a unit-system.  This function must be called before
the first call to @code{ut_offset_by_time()} for a unit in the same unit-system.
@code{@ref{ut_read_xml()}} calls this function if the
unit-system it's reading contains a unit named ``second''.
This function returns one of the following:

@table @code
@item UT_SUCCESS
The ``second'' unit of @var{system} was successfully set.
@item UT_EXISTS
The ``second'' unit of @var{system} is set to a different unit.
@item UT_BAD_ARG
@var{second} is @code{NULL}.
@end table
@end deftypefun

@node Value Conversion, Parsing, Unit-Systems, Top
@chapter Converting Values Between Units
@cindex converting values between units
@cindex unit conversion

You can convert numeric values in one unit to equivalent values in
another, compatible unit by means of a converter.
For example

@example
#include <udunits2.h>
...
    ut_unit*      from = ...;
    ut_unit*      to = ...;
    cv_converter* converter = ut_get_converter(from, to);
    double       fromValue = ...;
    double       toValue = cv_convert_double(converter, fromValue);

    cv_free(converter);
@end example

The converter API is declared in the header-file @code{<converter.h>},
which is automatically included by the UDUNITS-2 header-file
(@code{<udunits2.h>}) so you don't need to explicitly include it.

@anchor{ut_are_convertible()}
@deftypefun @code{int} ut_are_convertible @code{(const ut_unit* @var{unit1}, uconst t_unit* @var{unit2})}
Indicates if numeric values in unit @var{unit1} are convertible to numeric
values in unit @var{unit2} via @ref{ut_get_converter()}.
In making this determination, dimensionless units are ignored.
This function returns a non-zero value if conversion is possible;
otherwise, @code{0} is returned and @ref{ut_get_status()} will return one
of the following:

@table @code
@item UT_BAD_ARG
@var{unit1} or @var{unit2} is @code{NULL}.
@item UT_NOT_SAME_SYSTEM
@var{unit1} and @var{unit2} belong to different @ref{unit-system}s.
@item UT_SUCCESS
Conversion between the units is not possible (e.g., @var{unit1} refers
to a meter and @var{unit2} refers to a kilogram.
@end table
@end deftypefun

@anchor{ut_get_converter()}
@deftypefun @code{cv_converter*} ut_get_converter @code{(ut_unit* const @var{from}, ut_unit* const @var{to})}
Creates and returns a converter of numeric values in the @var{from} unit
to equivalent values in the @var{to} unit.
You should pass the returned pointer to @code{cv_free()} when you
no longer need the converter.
If an error occurs,
then this function writes an error-message using
@code{@ref{ut_handle_error_message()}}
and returns @code{NULL}.
Also, @code{@ref{ut_get_status()}} will return one of the following:

@table @code
@item UT_BAD_ARG
@var{from} or @var{to} is @code{NULL}.
@item UT_NOT_SAME_SYSTEM
The units @var{from} and @var{to} don't belong to the same unit-system.
@item UT_MEANINGLESS
The units belong to the same unit-system but conversion between them is
meaningless (e.g., conversion between seconds and kilograms is meaningless).
@item UT_OS
Operating-system failure.  See @code{errno}.
@end table
@end deftypefun

@anchor{cv_convert_float()}
@deftypefun @code{float} cv_convert_float @code{(const cv_converter* @var{converter}, const float @var{value})}
Converts the single floating-point value @var{value} and
returns the new value.
@end deftypefun

@anchor{cv_convert_double()}
@deftypefun @code{double} cv_convert_double @code{(const cv_converter* @var{converter}, const double @var{value})}
Converts the single double-precision value @var{value} and
returns the new value.
@end deftypefun

@anchor{cv_convert_floats()}
@deftypefun @code{float*} cv_convert_floats @code{(const cv_converter* @var{converter}, const float* @var{in}, size_t @var{count}, float* @var{out})}
Converts the @var{count} floating-point values starting at @var{in}, writing
the new values starting at @var{out} and, as a convenience,
returns @var{out}.
The input and output arrays may overlap or be identical.
@end deftypefun

@anchor{cv_convert_doubles()}
@deftypefun @code{double*} cv_convert_doubles @code{(const cv_converter* @var{converter}, const double* @var{in}, size_t @var{count}, double* @var{out})}
Converts the @var{count} double-precision values starting at @var{in}, writing
the new values starting at @var{out} and, as a convenience,
returns @var{out}.
The input and output arrays may overlap or be identical.
@end deftypefun

@anchor{cv_free()}
@deftypefun @code{void} cv_free @code{(cv_converter* @var{conv})};
Frees resources associated with the converter referenced by @var{conv}.
You should call this function when you no longer need the converter.
Use of @var{conv} upon return results in undefined behavior.
@end deftypefun

@node Parsing, Syntax, Value Conversion, Top
@chapter Parsing a String into a Unit
@cindex parsing a string into a unit
@cindex string, parsing into a unit

Here's an example of parsing a string representation of a unit into
its binary representation:

@example
#include <stdlib.h>
#include <udunits2.h>
...
    ut_system*   unitSystem = @ref{ut_read_xml(),ut_read_xml(NULL)};
    const char* string = "kg.m2/s3";
    ut_unit*     watt = @ref{ut_parse(),ut_parse}(unitSystem, string, UT_ASCII);

    if (watt == NULL) @{
        /* Unable to parse string. */
    @}
    else @{
        /* Life is good. */
    @}
@end example

@anchor{ut_parse()}
@deftypefun @code{ut_unit*} ut_parse @code{(const ut_system* @var{system}, const char* @var{string}, ut_encoding @var{encoding})}
Returns the binary unit representation corresponding to the string unit
representation @var{string} in the character-set @var{encoding} using the
unit-system @var{system}.
@var{string} must have no leading or trailing whitespace (see
@code{@ref{ut_trim()}}).
If an error occurs, then this function returns @code{NULL} and
@code{@ref{ut_get_status()}} will return one of the following:

@table @code
@item UT_BAD_ARG
@var{system} or @var{string} is @code{NULL}.
@item UT_SYNTAX
@var{string} contained a syntax error.
@item UT_UNKNOWN
@var{string} contained an unknown identifier.
@item UT_OS
Operating-system failure.  See @code{errno} for the reason.
@end table
@end deftypefun

@anchor{ut_trim()}
@deftypefun @code{size_t} ut_trim @code{(char* @var{string}, ut_encoding @var{encoding})}
Removes all leading and trailing whitespace from the NUL-terminated string
@var{string}.  Returns @var{string}, which is modified if it contained leading
or trailing whitespace.
@end deftypefun

@node Syntax, Formatting, Parsing, Top
@chapter Unit Syntax
@cindex unit syntax
@cindex syntax, unit

For the most part, the UDUNITS-2 package follows the syntax for unit-strings
promulgated by the US National Institute for Standards and Technology (NIST).
Details, of which, can be found at @uref{http://physics.nist.gov/cuu/Units/index.html}.
The one general exception to this is the invention of a syntax for
``offset''-units (e.g., the definition of the degree Celsius is ``K @@
273.15'').

@menu
* Examples::  Examples of unit specifications
* Grammar::   Formal unit grammar
@end menu

@node Examples, Grammar, , Syntax
@section Unit Specification Examples
@cindex unit specification examples
@cindex examples, unit specification

@quotation
@multitable {Logarithmic} {(5 meter)/(30 second)} {lg(re mW)} {"lg" is base 10, "ln" is base e, and "lb" is base 2}
@headitem String Type @tab Using Names @tab Using Symbols @tab Comment
@item Simple @tab meter @tab m
@item Raised @tab meter^2 @tab m2 @tab higher precedence than multiplying or
dividing
@item Product @tab newton meter @tab N.m
@item Quotient @tab meter per second @tab m/s
@item Scaled @tab 60 second @tab 60 s
@item Prefixed @tab kilometer @tab km
@item Offset @tab kelvin from 273.15 @tab K @@ 273.15 @tab lower
precedence than multiplying or dividing
@item Logarithmic @tab lg(re milliwatt) @tab lg(re mW) @tab "lg" is base 10, 
"ln" is base e, and "lb" is base 2
@item Grouped @tab (5 meter)/(30 second) @tab (5 m)/(30 s)
@end multitable
@end quotation

The above may be combined, e.g., "0.1 lg(re m/(5 s)^2) @@ 50".

You may also look at the @code{<def>} elements in @ref{Database,the
units database} to see examples of string unit specifications.

You may use the @code{@ref{Top, , udunits2, udunits2prog}} utility 
to experiment with string unit specifications.

@node Grammar, , Examples, Syntax
@section Unit Grammar
@cindex unit grammar
@cindex grammar, unit

Here is the unit-syntax understood by the UDUNITS-2 package.  Words printed
@emph{Thusly} indicate non-terminals; words printed THUSLY indicate terminals;
and words printed <thusly> indicate lexical elements.

@example
@emph{Unit-Spec: one of}
        nothing
        @emph{Shift-Spec}

@emph{Shift-Spec: one of}
        @emph{Product-Spec}
        @emph{Product-Spec} SHIFT REAL
        @emph{Product-Spec} SHIFT INT
        @emph{Product-Spec} SHIFT @emph{Timestamp}

@emph{Product-Spec: one of}
        @emph{Power-Spec}
        @emph{Product-Spec} @emph{Power-Spec}
        @emph{Product-Spec} MULTIPLY @emph{Power-Spec}
        @emph{Product-Spec} DIVIDE @emph{Power-Spec}

@emph{Power-Spec: one of}
        @emph{Basic-Spec}
        @emph{Basic-Spec} INT
        @emph{Basic-Spec} EXPONENT
        @emph{Basic-Spec} RAISE INT

@emph{Basic-Spec: one of}
        ID
        "(" @emph{Shift-Spec} ")"
        LOGREF @emph{Product_Spec} ")"
        @emph{Number}

@emph{Number: one of}
        INT
        REAL

@emph{Timestamp: one of}
        DATE
        DATE CLOCK
        DATE CLOCK CLOCK
        DATE CLOCK INT
        DATE CLOCK ID
        TIMESTAMP
        TIMESTAMP INT
        TIMESTAMP ID

SHIFT:
        <space>* <shift_op> <space>*

<shift_op>: one of
        "@@"
        "after"
        "from"
        "since"
        "ref"

REAL:
        the usual floating-point format

INT:
        the usual integer format

MULTIPLY: one of
        "-"
        "."
        "*"
        <space>+
        <centered middot>

DIVIDE:
        <space>* <divide_op> <space>*

<divide_op>: one of
        per
        PER
        "/"

EXPONENT:
        ISO-8859-9 or UTF-8 encoded exponent characters

RAISE: one of
        "^"
        "**"

ID: one of
        <id>
        "%"
        "'"
        "\""
        degree sign
        greek mu character

<id>:
        <alpha> <alphanum>*

<alpha>:
        [A-Za-z_]
        ISO-8859-1 alphabetic characters
        non-breaking space

<alphanum>: one of
        <alpha>
        <digit>

<digit>:
        [0-9]

LOGREF:
        <log> <space>* <logref>

<log>: one of
        "log"
        "lg"
        "ln"
        "lb"

<logref>:
        "(" <space>* <re> ":"? <space>*

DATE:
        <year> "-" <month> ("-" <day>)?

<year>:
        [+-]?[0-9]@{1,4@}

<month>:
        "0"?[1-9]|1[0-2]

<day>:
        "0"?[1-9]|[1-2][0-9]|"30"|"31"

CLOCK:
        <hour> ":" <minute> (":" <second>)?

TIMSTAMP:
        <year> (<month> <day>?)? "T" <hour> (<minute> <second>?)?

<hour>:
        [+-]?[0-1]?[0-9]|2[0-3]

<minute>:
        [0-5]?[0-9]

<second>:
        (<minute>|60) (\.[0-9]*)?

@end example

@node Formatting, Operations, Syntax, Top
@chapter Formatting a Unit into a String
@cindex formatting a unit into a string
@cindex unit, formatting into a string
@cindex string, formatting a unit into a

Use the @code{@ref{ut_format()}} function to obtain the string representation
of a binary unit.
For example, the following gets the definition of the unit "watt" in
ASCII characters using unit-symbols rather than unit-names:

@example
ut_unit*     watt = ...;
char        buf[128];
unsigned    opts = @ref{ut_encoding,UT_ASCII} | UT_DEFINITION;
int         len = @ref{ut_format(),ut_format}(watt, buf, sizeof(buf), opts);

if (len == -1) @{
    /* Couldn't get string */
@}
else if (len == sizeof(buf)) @{
    /* Entire buffer used: no terminating NUL */
@}
else @{
    /* Have string with terminating NUL */
@}
@end example

@anchor{ut_format()}
@deftypefun @code{int} ut_format @code{(const ut_unit* @var{unit}, char* @var{buf}, size_t @var{size}, unsigned @var{opts})}
Formats the unit @var{unit} (i.e., returns its string representation)
into the buffer pointed-to by @var{buf} of size @var{size}.
The argument @var{opts} specifies how the formatting is to be done and
is a bitwise OR of a @ref{ut_encoding} value and zero or more of the following:

@table @code
@item UT_NAMES
Use unit names instead of symbols.
@item UT_DEFINITION
The formatted string should be the definition of @var{unit} in terms
of basic-units instead of stopping any expansion at the highest level
possible.
@end table

On success, this function returns either the number of bytes -- excluding the
terminating @code{NUL} -- that were written into @code{buf} or the number of
bytes that @emph{would have been written}. The difference is due to the
the runtime @code{snprinf()} function that was used.

On failure, this function returns @code{-1} and @ref{ut_get_status()} will
return one of the following:

@table @code
@item UT_BAD_ARG
@var{unit} or @var{buf} is @code{NULL}, or 
@var{opts} contains the bit patterns of both @code{UT_LATIN1} and
@code{UT_UTF8}.
@item UT_CANT_FORMAT
@var{unit} can't be formatted in the desired manner (e.g., @var{opts}
contains @code{UT_ASCII} but @var{unit} doesn't have an identifier in
that character-set or @var{opts} doesn't contain UT_NAMES and a necessary
symbol doesn't exist).
@end table
@end deftypefun

@node Operations, Mapping, Formatting, Top
@chapter Unit Operations
@cindex unit operations
@cindex operations, unit

You can use unit operations to construct new units, get information
about units, or compare units.

@menu
* Unary::       Operations on a single unit
* Binary::      Operations on pairs of units
@end menu

@node Unary, Binary, , Operations
@section Unary Unit Operations
@cindex unary unit operations

@anchor{ut_free()}
@deftypefun @code{void} ut_free @code{(ut_unit* @var{unit})}
Frees resources associated with @var{unit}.
You should invoke this function on every unit that you no longer need.
Use of @var{unit} upon
return from this function results in undefined behavior.
@end deftypefun

@anchor{ut_scale()}
@deftypefun @code{ut_unit*} ut_scale @code{(double @var{factor}, const ut_unit* @var{unit})}
Returns a unit equivalent to another unit scaled by a numeric factor.
For example:
@example
const ut_unit*   meter = ...
const ut_unit*   kilometer = ut_scale(1000, meter);
@end example
The returned unit is equivalent to @var{unit} multiplied by
@var{factor}.
You should pass the returned pointer to @code{@ref{ut_free()}} when you
no longer need the unit.
@end deftypefun

@anchor{ut_offset()}
@deftypefun @code{ut_unit*} ut_offset @code{(const ut_unit* @var{unit}, double @var{offset})}
Returns a unit equivalent to another unit relative to a particular
origin.
For example:
@example
const ut_unit*   kelvin = ...
const ut_unit*   celsius = ut_offset(kelvin, 273.15);
@end example
The returned unit is equivalent to @var{unit} with an origin of
@var{offset}.
You should pass the returned pointer to @code{@ref{ut_free()}} when you
no longer need the unit.
If an error occurs, then this function returns @code{NULL} and
@code{@ref{ut_get_status()}} will return one of the following:

@table @code
@item UT_BAD_ARG
@var{unit} is @code{NULL}.
@item UT_OS
Operating-system error.  See @code{errno} for the reason.
@end table
@end deftypefun

@anchor{ut_offset_by_time()}
@deftypefun @code{ut_unit*} ut_offset_by_time @code{(const ut_unit* const @var{unit}, const double @var{origin})}
Returns a timestamp-unit equivalent to the time unit @var{unit}
referenced to the time-origin @var{origin} (as returned by
@code{@ref{ut_encode_time()}}).
For example:
@example
const ut_unit*   second = ...
const ut_unit*   secondsSinceTheEpoch =
    ut_offset_by_time(second, ut_encode_time(1970, 1, 1, 0, 0, 0.0));
@end example
Leap seconds are not taken into account.
You should pass the returned pointer to @code{@ref{ut_free()}} when you
no longer need the unit.
If an error occurs, then this function returns @code{NULL} and
@code{@ref{ut_get_status()}} will return one of the following:

@table @code
@item UT_BAD_ARG
@var{unit} is @code{NULL}.
@item UT_OS
Operating-system error.  See @code{errno} for the reason.
@item UT_MEANINGLESS
Creation of a timestamp unit based on @var{unit} is not meaningful.  It
might not be a time-unit, for example.
@item UT_NO_SECOND
The associated unit-system doesn't contain a ``second'' unit.  See
@code{@ref{ut_set_second()}}.
@end table

@strong{CAUTION:}
The timestamp-unit was created to be analogous to, for example, the degree
celsius---but for the time dimension.
I've come to believe, however, that creating
such a unit was a mistake, primarily because users try to use the unit in
ways for which it was not designed (such as converting dates in a
calendar whose year is exactly 365 days long).
Such activities are much better handled by a dedicated calendar package.
Please be careful about using timestamp-units.
See also the section on @ref{Time, The Handling of Time}.

@end deftypefun

@anchor{ut_invert()}
@deftypefun @code{ut_unit*} ut_invert @code{(const ut_unit* @var{unit})}
Returns the inverse (i.e., reciprocal) of the unit @var{unit}.
This convenience function is equal to 
@code{@ref{ut_raise(),ut_raise(@var{unit}@comma{}-1)}}.
You should pass the returned pointer to @code{@ref{ut_free()}} when you
no longer need the unit.
If an error occurs,
then this function writes an error-message using
@code{@ref{ut_handle_error_message()}}
and returns @code{NULL}.
Also, @code{@ref{ut_get_status()}} will return one of the following:

@table @code
@item UT_BAD_ARG
@var{unit} is @code{NULL}.
@item UT_OS
Operating-system error. See @code{errno} for the reason.
@end table
@end deftypefun

@anchor{ut_raise()}
@deftypefun @code{ut_unit*} ut_raise @code{(const ut_unit* @var{unit}, int @var{power})}
Returns the unit equal to unit @var{unit} raised to the power @var{power}.
You should pass the returned pointer to @code{ut_free()} when you
no longer need the unit.
If an error occurs,
then this function writes an error-message using
@code{@ref{ut_handle_error_message()}}
and returns @code{NULL}.
Also, @code{@ref{ut_get_status()}} will return one of the following:

@table @code
@item UT_BAD_ARG
@var{unit} is @code{NULL}.
@item UT_OS
Operating-system error. See @code{errno} for the reason.
@end table
@end deftypefun

@anchor{ut_root()}
@deftypefun @code{ut_unit*} ut_root @code{(const ut_unit* @var{unit}, int @var{root})}
Returns the unit equal to the @var{root} root of unit @var{unit}.
You should pass the returned pointer to @code{ut_free()} when you
no longer need the unit.
If an error occurs,
then this function writes an error-message using
@code{@ref{ut_handle_error_message()}}
and returns @code{NULL}.
Also, @code{@ref{ut_get_status()}} will return one of the following:

@table @code
@item UT_BAD_ARG
@var{unit} is @code{NULL}.
@item UT_MEANINGLESS
It's meaningless to take the given root of the given unit.
This could be because the
resulting unit would have fractional (i.e., non-integral) dimensionality,
or because the unit is, for example, a logarithmic unit.
@item UT_OS
Operating-system error. See @code{errno} for the reason.
@end table
@end deftypefun

@anchor{ut_log()}
@deftypefun @code{ut_unit*} ut_log @code{(double @var{base}, const ut_unit* @var{reference})}
Returns the logarithmic unit corresponding to the logarithmic base
@var{base} and a reference level specified as the unit @var{reference}.
For example, the following creates a decibel unit with a
one milliwatt reference level:
@example
     const ut_unit* milliWatt = ...;
     const ut_unit* bel_1_mW = ut_log(10.0, milliWatt);

     if (bel_1_mW != NULL) @{
         const ut_unit* decibel_1_mW = @ref{ut_scale(),ut_scale}(0.1, bel_1_mW);

         @ref{ut_free(),ut_free}(bel_1_mW);   /* no longer needed */

         if (decibel_1_mW != NULL) @{
             /* Have decibel unit with 1 mW reference */
             ...
             @ref{ut_free(),ut_free}(decibel_1_mW);
         @}                 /* "decibel_1_mW" allocated */
     @}
@end example
You should pass the returned pointer to @code{ut_free()} when you
no longer need the unit.
If an error occurs,
then this function writes an error-message using
@code{@ref{ut_handle_error_message()}}
and returns @code{NULL}.
Also, @code{@ref{ut_get_status()}} will return one of the following:

@table @code
@item UT_BAD_ARG
@var{reference} is @code{NULL}.
@item UT_OS
Operating-system error. See @code{errno} for the reason.
@item UT_BAD_ARG
@var{base} is invalid (e.g., it must be greater than one).
@end table
@end deftypefun

@anchor{ut_get_name()}
@deftypefun @code{const char*} ut_get_name @code{(const ut_unit* @var{unit}, ut_encoding @var{encoding})}
Returns the name to which the unit referenced by @var{unit} maps in the
character-encoding specified by @var{encoding}.
If this function returns @code{NULL}, then
@code{@ref{ut_get_status()}} will return
one of the following:

@table @code
@item UT_BAD_ARG
@var{name} is @code{NULL}.
@item UT_SUCCESS
@var{unit} doesn't map to a name in the given character-set.
@end table
@end deftypefun

@anchor{ut_get_symbol()}
@deftypefun @code{const char*} ut_get_symbol @code{(const ut_unit* @var{unit}, ut_encoding @var{encoding})}
Returns the symbol to which the unit referenced by @var{unit} maps in the
character-encoding specified by @var{encoding}.
If this function returns @code{NULL}, then
@code{@ref{ut_get_status()}} will return
one of the following:

@table @code
@item UT_BAD_ARG
@var{symbol} is @code{NULL}.
@item UT_SUCCESS
@var{unit} doesn't map to a symbol in the given character-set.
@end table
@end deftypefun

@anchor{ut_get_system()}
@deftypefun @code{ut_system*} ut_get_system @code{(const ut_unit* @var{unit})}
Returns the unit-system to which the unit referenced by @var{unit} belongs.
If @var{unit} is @code{NULL}, then this function writes an error-message
using @code{@ref{ut_handle_error_message()}}
and returns @code{NULL}.
Also, @code{@ref{ut_get_status()}} will return @code{UT_BAD_ARG}.
@end deftypefun

@anchor{ut_is_dimensionless()}
@deftypefun @code{int} ut_is_dimensionless @code{(const ut_unit* @var{unit})}
Indicates if unit @var{unit} is dimensionless (like ``radian'').
This function returns a non-zero value if the unit is dimensionfull;
otherwise, @code{0} is returned and
@ref{ut_get_status()} will return one of the following:

@table @code
@item UT_BAD_ARG
@var{unit1} is @code{NULL}.
@item UT_SUCCESS
The unit is dimensionless.
@end table
@end deftypefun

@anchor{ut_clone()}
@deftypefun @code{ut_unit*} ut_clone @code{(const ut_unit* @var{unit})}
Returns a copy of the unit referenced by @var{unit}.
You should pass the returned pointer to @code{ut_free()} when you
no longer need the unit.
If an error occurs,
then this function writes an error-message using
@code{@ref{ut_handle_error_message()}}
and returns @code{NULL}.
Also, @code{@ref{ut_get_status()}} will return one of the following:

@table @code
@item UT_BAD_ARG
@var{unit} is @code{NULL}.
@item UT_OS
Operating-system failure.  See @code{errno}.
@end table
If you use @code{@ref{ut_read_xml()}}, then you should not normally
need to call this function.
@end deftypefun

@anchor{ut_accept_visitor()}
@deftypefun @code{@ref{ut_status}} ut_accept_visitor @code{(const ut_unit* @var{unit}, const @ref{ut_visitor,ut_visitor}* @var{visitor}, void* @var{arg})}
Accepts the visitor @var{visitor} to the unit @var{unit}.
The argument @var{arg} is passed to the visitor's functions.
This function returns one of the following:

@table @code
@item UT_BAD_ARG
@var{visitor} or @var{unit} is @code{NULL}.
@item UT_VISIT_ERROR
An error occurred in @var{visitor} while visiting @var{unit}.
@item UT_SUCCESS
Success.
@end table
@end deftypefun

@anchor{ut_visitor}
@deftp {Data type} {ut_visitor} {int foo(int)} {int bar(int, int)}
You pass a pointer to a data object of this type if and when you call
@code{@ref{ut_accept_visitor()}}.
It contains the following pointers to functions that implement your
unit-visitor:

@table @code
@item @ref{ut_status} (*visit_basic)(const ut_unit* @var{unit}, void* @var{arg}); 
Visits the basic-unit @var{unit}.  A basic-unit is a base unit like
``meter'' or a non-dimensional but named unit like ``radian''.
This function returns @code{@ref{ut_status,UT_SUCCESS}} on and only on success.
@item @ref{ut_status} (*visit_product)(const ut_unit* @var{unit}, int @var{count}, const ut_unit* const* @var{basicUnits}, const int* @var{powers}, void* @var{arg}); 
Visits the product-unit @var{unit}.
The product-unit is a product of the @var{count}
basic-units referenced by @var{basicUnits}, each raised to their respective,
non-zero power in @var{powers}.
This function returns @code{@ref{ut_status,UT_SUCCESS}} on and only on success.
@item @ref{ut_status} (*visit_galilean)(const ut_unit* @var{unit}, double @var{scale}, const ut_unit* @var{underlyingUnit}, double @var{origin}, void* arg); 
Visits the Galilean-unit @var{unit}.
The Galilean-unit has the underlying unit @var{underlyingUnit} and either the
non-unity scale factor @var{scale} or the non-zero origin @var{origin}, or both.
This function returns @code{@ref{ut_status,UT_SUCCESS}} on and only on success.
@item @ref{ut_status} (*visit_timestamp)(const ut_unit* @var{unit}, const ut_unit* @var{timeUnit}, double @var{origin}, void* @var{arg}); 
Visits the timestamp-unit @var{unit}.
The timestamp-unit has the underlying unit of time @var{timeUnit}
and the @code{@ref{ut_encode_time()}}-encoded time-origin @var{origin}.
This function returns @code{@ref{ut_status,UT_SUCCESS}} on and only on success.
@item @ref{ut_status} (*visit_logarithmic)(const ut_unit* @var{unit}, double @var{base}, const ut_unit* @var{reference}, void* @var{arg}); 
Visits the logarithmic-unit @var{unit}.
The logarithmic-unit has the logarithmic base @var{base} and
the reference-level is specified by the unit @var{reference}.
This function returns @code{@ref{ut_status,UT_SUCCESS}} on and only on success.
@end table
@end deftp

@node Binary, , Unary, Operations
@section Binary Unit Operations
@cindex binary unit operations

Binary unit operations act on two units.

@strong{NOTE:} The functions
@code{@ref{ut_are_convertible()}} and @code{@ref{ut_get_converter()}} are also
binary unit operations but are documented elsewhere.

@anchor{ut_multiply()}
@deftypefun @code{ut_unit*} ut_multiply @code{(const ut_unit* @var{unit1}, const ut_unit* @var{unit2})}
Returns the result of multiplying unit @var{unit1} by unit @var{unit2}.
You should pass the pointer to @ref{ut_free()} when you no longer need the unit
On failure, this function returns @code{NULL} and @ref{ut_get_status()}
will return one of the following:

@table @code
@item UT_BAD_ARG
@var{unit1} or @var{unit2} is @code{NULL}.
@item UT_NOT_SAME_SYSTEM
@var{unit1} and @var{unit2} belong to different @ref{unit-system}s.
@item UT_OS
Operating-system error. See @var{errno} for the reason.
@end table
@end deftypefun

@anchor{ut_divide}
@deftypefun @code{ut_unit*} ut_divide @code{(const ut_unit* @var{numer}, const ut_unit* @var{denom})}
Returns the result of dividing unit @var{numer} by unit @var{denom}.
You should pass the pointer to @ref{ut_free()} when you no longer need the unit
On failure, this function returns @code{NULL} and @ref{ut_get_status()} 
will return one of the following:

@table @code
@item UT_BAD_ARG
@var{numer} or @var{denom} is @code{NULL}.
@item UT_NOT_SAME_SYSTEM
@var{unit1} and @var{unit2} belong to different @ref{unit-system}s.
@item UT_OS
Operating-system error. See @code{errno} for the reason.
@end table
@end deftypefun

@anchor{ut_compare()}
@deftypefun @code{int} ut_compare @code{(const ut_unit* @var{unit1}, const ut_unit* @var{unit2})}
Compares two units.  Returns a value less than, equal to, or greater than
zero as @var{unit1} is considered less than, equal to, or greater than
@var{unit2}, respectively.
Units from different @ref{unit-system}s never compare equal.
The value zero is also returned if both unit pointers are @code{NULL}.
@end deftypefun

@anchor{ut_same_system()}
@deftypefun @code{int} ut_same_system @code{(const ut_unit* @var{unit1}, const ut_unit* @var{unit2})}
Indicates if two units belong to the same unit-system.
This function returns a non-zero value if the two units belong to the
same @ref{unit-system}; otherwise, @code{0} is returned and
@ref{ut_get_status()} will return one of the following:

@table @code
@item UT_BAD_ARG
@var{unit1} or @var{unit2} is @code{NULL}.
@item UT_SUCCESS
The units belong to different @ref{unit-system}s.
@end table
@end deftypefun

@node Mapping, Time, Operations, Top
@chapter Mapping Between Identifiers and Units
@cindex mapping units
@cindex mapping identifiers
@cindex units, mapping to identifiers

Within a unit-system, you can map an identifier to a unit and vice
versa.
If an identifier maps to a unit, then the unit can be retrieved from the
unit-system via the identifier.
Similarly, if a unit maps to an identifier, then the unit can be printed
using the identifier.

There a two kinds of identifiers: names and symbols.

@menu
* Names::       Mapping between units and names.
* Symbols::     Mapping between units and symbols.
@end menu

@node Names, Symbols, , Mapping
@section Names
@cindex names

You can map a name to a unit and vice versa.  If you use
@code{@ref{ut_read_xml()}}, then you shouldn't normally need to do this.

@anchor{ut_map_name_to_unit()}
@deftypefun @code{@ref{ut_status}} ut_map_name_to_unit @code{(const char* @var{name}, const ut_encoding @var{encoding}, const ut_unit* @var{unit})}
Maps the name referenced by @var{name}, in character-set @var{encoding},
to the unit referenced by @var{unit}
in the unit-system that contains @var{unit}.
This function returns one of the following:

@table @code
@item UT_SUCCESS
Success.
@item UT_BAD_ARG
@var{name} or @var{unit} is @code{NULL}.
@item UT_OS
Operating-system failure.  See @code{errno}.
@item UT_EXISTS
@var{name} already maps to a different unit.
@end table
@end deftypefun

@anchor{ut_unmap_name_to_unit()}
@deftypefun @code{@ref{ut_status}} ut_unmap_name_to_unit @code{(ut_system* @var{system}, const char* @var{name}, const ut_encoding @var{encoding})}
Removes any mapping from name @var{name}, in character-set @var{encoding}, to a unit in unit-system @var{system}.
This function returns one of the following:

@table @code
@item UT_SUCCESS
Success.
@item UT_BAD_ARG
@var{system} or @var{name} is @code{NULL}.
@end table
@end deftypefun

@anchor{ut_map_unit_to_name()}
@deftypefun @code{@ref{ut_status}} ut_map_unit_to_name @code{(const ut_unit* @var{unit}, const char* @var{name}, ut_encoding @var{encoding})}
Maps the unit @var{unit} to the name @var{name}, which is in character-set
@var{encoding}, in the unit-system that contains the unit.
This function returns one of the following:

@table @code
@item UT_SUCCESS
Success.
@item UT_BAD_ARG
@var{unit} or @var{name} is @code{NULL}, or @var{name} is not in the
character-set @var{encoding}.
@item UT_OS
Operating-system failure.  See @code{errno}.
@item UT_EXISTS
@var{unit} already maps to a different name.
@end table
@end deftypefun

@anchor{ut_unmap_unit_to_name()}
@deftypefun @code{@ref{ut_status}} ut_unmap_unit_to_name @code{(const ut_unit* @var{unit}, ut_encoding @var{encoding})}
Removes any mapping from unit @var{unit} to a name in character-set
@var{encoding} from the unit-system that contains the unit.
This function returns one of the following:

@table @code
@item UT_SUCCESS
Success.
@item UT_BAD_ARG
@var{unit} is @code{NULL}.
@end table
@end deftypefun

@node Symbols, , Names, Mapping
@section Symbols
@cindex symbols

You can map a symbol to a unit and vice versa.  If you use
@code{@ref{ut_read_xml()}}, then you shouldn't normally need to do this.

@anchor{ut_map_symbol_to_unit()}
@deftypefun @code{@ref{ut_status}} ut_map_symbol_to_unit @code{(const char* @var{symbol}, const ut_encoding @var{encoding}, const ut_unit* @var{unit})}
Maps the symbol referenced by @var{symbol}, in character-set @var{encoding},
to the unit referenced by @var{unit}
in the unit-system that contains @var{unit}.
This function returns one of the following:

@table @code
@item UT_SUCCESS
Success.
@item UT_BAD_ARG
@var{symbol} or @var{unit} is @code{NULL}.
@item UT_OS
Operating-system failure.  See @code{errno}.
@item UT_EXISTS
@var{symbol} already maps to a different unit.
@end table
@end deftypefun

@anchor{ut_unmap_symbol_to_unit()}
@deftypefun @code{@ref{ut_status}} ut_unmap_symbol_to_unit @code{(ut_system* @var{system}, const char* @var{symbol}, const ut_encoding @var{encoding})}
Removes any mapping from symbol @var{symbol}, in character-set @var{encoding}, to a unit in unit-system @var{system}.
This function returns one of the following:

@table @code
@item UT_SUCCESS
Success.
@item UT_BAD_ARG
@var{system} or @var{symbol} is @code{NULL}.
@end table
@end deftypefun

@anchor{ut_map_unit_to_symbol()}
@deftypefun @code{@ref{ut_status}} ut_map_unit_to_symbol @code{(const ut_unit* @var{unit}, const char* @var{symbol}, ut_encoding @var{encoding})}
Maps the unit @var{unit} to the symbol @var{symbol}, which is in character-set
@var{encoding}, in the unit-system that contains the unit.
This function returns one of the following:

@table @code
@item UT_SUCCESS
Success.
@item UT_BAD_ARG
@var{unit} or @var{symbol} is @code{NULL}.
@item UT_BAD_ARG
Symbol @var{symbol} is not in the character-set @var{encoding}.
@item UT_OS
Operating-system failure.  See @code{errno}.
@item UT_EXISTS
@var{unit} already maps to a different symbol.
@end table
@end deftypefun

@anchor{ut_unmap_unit_to_symbol()}
@deftypefun @code{@ref{ut_status}} ut_unmap_unit_to_symbol @code{(const ut_unit* @var{unit}, ut_encoding @var{encoding})}
Removes any mapping from unit @var{unit} to a symbol in character-set
@var{encoding} from the unit-system that contains the unit.
This function returns one of the following:

@table @code
@item UT_SUCCESS
Success.
@item UT_BAD_ARG
@var{unit} is @code{NULL}.
@end table
@end deftypefun

@node Time, Errors, Mapping, Top
@chapter The Handling of Time
@cindex time, handling of

You should use a true calendar package rather than the UDUNITS-2 package 
to handle time.  Having said that, many people use the time-handling
capabilities of the UDUNITS-2 package because it supports "units" like
"@code{seconds since 1970-01-01}".  You should be aware, however, that the
hybrid Gregorian/Julian calendar used by the UDUNITS-2 package @emph{cannot be
changed}.  Dates on or after 1582-10-15 are assumed to be Gregorian dates;
dates before that are assumed to be Julian dates.  In particular,
the year 1 BCE is immediately followed by the year 1 CE.

In general, the UDUNITS-2 package handles time by encoding it as
double-precision value, which can then be acted upon arithmetically.

@anchor{ut_encode_time()}
@deftypefun @code{double} ut_encode_time @code{(int @var{year}, int @var{month}, int @var{day}, int @var{hour}, int @var{minute}, double @var{second})}
Encodes a time as a double-precision value.
This convenience function is equivalent to
@example
@ref{ut_encode_date(),ut_encode_date}(@var{year},@var{month},@var{day}) + @ref{ut_encode_clock(),ut_encode_clock}(@var{hour},@var{minute},@var{second})
@end example
@end deftypefun

@anchor{ut_encode_date()}
@deftypefun @code{double} ut_encode_date @code{(int @var{year}, int @var{month}, int @var{day})}
Encodes a date as a double-precision value.
You probably won't use this function.
Dates on or after 1582-10-15 are assumed to be Gregorian dates;
dates before that are assumed to be Julian dates.  In particular,
the year 1 BCE is immediately followed by the year 1 CE.
@end deftypefun

@anchor{ut_encode_clock()}
@deftypefun @code{double} ut_encode_clock @code{(int @var{hour}, int @var{minute}, double @var{second})}
Encodes a clock-time as a double-precision value.
You probably won't use this function.
@end deftypefun

@anchor{ut_decode_time()}
@deftypefun @code{void} ut_decode_time @code{(double @var{time}, int* @var{year}, int* @var{month}, int* @var{day}, int* @var{hour}, int* @var{minute}, double* @var{second}, double* @var{resolution})}
Decodes a time from a double-precision value into its individual components.
The variable referenced by @var{resolution} will be set to the resolution
(i.e., uncertainty) of the time in seconds.
@end deftypefun

@node Errors, Database, Time, Top
@chapter Error Handling
@cindex error handling

Error-handling in the units module has two aspects: the status of
the last operation performed by the module and the handling of error-messages:

@menu
* Status::      The status of the last operation.
* Messages::    The handling of error-messages.
@end menu

@node Status, Messages, , Errors
@section Status of Last Operation
@cindex status of last operation
@cindex module status

UDUNITS-2 functions set their status by calling @code{@ref{ut_set_status()}}.
You can use the function @code{@ref{ut_get_status()}} to retrieve that
status.

@anchor{ut_get_status()}
@deftypefun @code{@ref{ut_status}} ut_get_status @code{(void)}
Returns the value specified in the last call to
@code{@ref{ut_set_status()}}
@end deftypefun

@anchor{ut_set_status()}
@deftypefun @code{void} ut_set_status @code{(@ref{ut_status} @var{status})}
Set the status of the units module to @var{status}.
@end deftypefun

@anchor{ut_status}
@deftp {Data type} {ut_status}
This enumeration has the following values:

@table @code
@item UT_SUCCESS
Success
@item UT_BAD_ARG
An argument violates the the function's contract (e.g., it's @code{NULL}).
@item UT_EXISTS
Unit, prefix, or identifier already exists
@item UT_NO_UNIT
No such unit exists
@item UT_OS
Operating-system error.  See @code{errno} for the reason.
@item UT_NOT_SAME_SYSTEM
The units belong to different unit-systems
@item UT_MEANINGLESS
The operation on the unit or units is meaningless
@item UT_NO_SECOND
The unit-system doesn't have a unit named ``second''
@item UT_VISIT_ERROR
An error occurred while visiting a unit
@item UT_CANT_FORMAT
A unit can't be formatted in the desired manner
@item UT_SYNTAX
String unit representation contains syntax error
@item UT_UNKNOWN
String unit representation contains unknown word
@item UT_OPEN_ARG
Can't open argument-specified unit database
@item UT_OPEN_ENV
Can't open environment-specified unit database
@item UT_OPEN_DEFAULT
Can't open installed, default, unit database
@item UT_PARSE
Error parsing unit database
@end table
@end deftp

@node Messages, , Status, Errors
@section Error-Messages
@cindex messages, error
@cindex error-messages

@anchor{ut_handle_error_message()}
@deftypefun @code{int} ut_handle_error_message @code{(const char* @var{fmt}, ...)}
Handles the error-message corresponding to the format-string @var{fmt} and
any subsequent arguments referenced by it.
The interpretation of the formatting-string is identical to that of
the UNIX function @code{printf()}.
On success, this function returns the number of bytes in the
error-message; otherwise, this function returns @code{-1}.

Use the function @code{@ref{ut_set_error_message_handler()}} to change how
error-messages are handled.
@end deftypefun

@anchor{ut_set_error_message_handler()}
@deftypefun @code{@ref{ut_error_message_handler}} ut_set_error_message_handler @code{(@ref{ut_error_message_handler} @var{handler})}
Sets the function that handles error-messages and returns the previous
error-message handler.
The initial error-message handler is @code{@ref{ut_write_to_stderr()}}.
@end deftypefun

@anchor{ut_write_to_stderr()}
@deftypefun @code{int} ut_write_to_stderr @code{(const char* @var{fmt}, va_list @var{args})}
Writes the variadic error-message
corresponding to formatting-string @var{fmt} and arguments @var{args}
to the standard-error stream and appends a newline.
The interpretation of the formatting-string is identical to that of
the UNIX function @code{printf()}.
On success, this function returns the number of bytes in the
error-message; otherwise, this function returns @code{-1}.
@end deftypefun

@anchor{ut_ignore()}
@deftypefun @code{int} ut_ignore @code{(const char* @var{fmt}, va_list @var{args})}
Does nothing.
In particular, it ignores the variadic error-message
corresponding to formatting-string @var{fmt} and arguments @var{args}.
Pass this function to @code{@ref{ut_set_error_message_handler()}} 
when you don't want the unit module to print any error-messages.
@end deftypefun

@anchor{ut_error_message_handler}
@deftp {Data type} {ut_error_message_handler}
This is the type of an error-message handler.
It's definition is
@example
typedef int (*ut_error_message_handler)(const char* fmt, va_list args);
@end example
@end deftp

@node Database, Types, Errors, Top
@chapter The Units Database
@cindex units database
@cindex database, units

The database of units that comes with the UDUNITS-2 package is an
XML-formatted file that is based on the SI system of units.
It contains the names and symbols of most of the units that you will ever
encounter.
The pathname of the installed file is
@code{@emph{datadir}/udunits2.xml}, where @emph{datadir} is the
installation-directory for read-only, architecture-independent data
(e.g., @code{/usr/local/share}).
This pathname is the default that @code{@ref{ut_read_xml()}} uses.

Naturally, because the database is a regular file, it can be edited
to add new units or remove existing ones.
Be very careful about doing this, however, because you might lose
the benefit of exchanging unit-based information with others who
haven't modified their database.

@node Types, Complete Index, Database, Top
@chapter Data Types
@cindex data types
@cindex types, data

The data types @code{@ref{ut_visitor}}, @code{@ref{ut_status}}, and
@code{@ref{ut_error_message_handler}} are documented elsewhere.

@anchor{ut_encoding}
@deftp {Data type} {ut_encoding}
This enumeration has the following values:

@table @code
@item UT_ASCII
@uref{http://en.wikipedia.org/wiki/Ascii,US ASCII} character-set.
@item UT_ISO_8859_1
The @uref{http://en.wikipedia.org/wiki/Iso-8859-1,ISO-8859-1} character-set.
@item UT_LATIN1
Synonym for @code{UT_ISO_8859_1}.
@item UT_UTF8
The @uref{http://en.wikipedia.org/wiki/Utf-8,UTF-8} encoding of the Unicode
character-set.
@end table
@end deftp

@node Complete Index, , Types, Top
@unnumbered Index

@printindex cp

@bye