source: trunk/test/src/RpUnitsC_test.c @ 40

Last change on this file since 40 was 40, checked in by dkearney, 15 years ago

initial add for test directory which will hold test cases for using rappture

File size: 3.6 KB
Line 
1#include "RpUnitsCInterface.h"
2#include <stdio.h>
3
4double fahrenheit2centigrade (double F);
5double centigrade2fahrenheit (double C);
6double centigrade2kelvin (double C);
7double kelvin2centigrade (double K);
8
9double angstrom2meter (double angstrom)
10{
11    return angstrom*1.0e-10;
12}
13
14double meter2angstrom (double meters)
15{
16    return meters*1.0e10;
17}
18
19double fahrenheit2centigrade (double F)
20{
21    return ((F-32.0)/(9.0/5.0));
22}
23
24double centigrade2fahrenheit (double C)
25{
26    return ((C*(9.0/5.0))+32.0);
27}
28
29double centigrade2kelvin (double C)
30{
31    return (C+273.15);
32}
33
34double kelvin2centigrade (double K)
35{
36    return (K-273.15);
37}
38
39int main()
40{
41
42    RpUnits* meters = defineUnit("m",NULL);
43
44    RpUnits* centimeters = NULL;
45    RpUnits* nanometers = NULL;
46    RpUnits* cm_basis = NULL;
47
48    RpUnits* angstrom = defineUnit("A",NULL);
49    RpUnits* fahrenheit = defineUnit("F",NULL);
50    RpUnits* celcius = defineUnit("C",NULL);
51    RpUnits* kelvin = defineUnit("K",NULL);
52
53    defineConv(angstrom, meters, angstrom2meter, meter2angstrom);
54    defineConv(fahrenheit, celcius, fahrenheit2centigrade, centigrade2fahrenheit);
55    defineConv(celcius, kelvin, centigrade2kelvin, kelvin2centigrade);
56   
57   
58    double cm_exp = 0;
59    double nm_conv = 0;
60    double value = 0;
61   
62    int result = 0;
63    int showUnits = 0;
64
65    const char* nm_conv_str;
66   
67    makeMetric(meters);
68    centimeters = find("cm");
69   
70    if (meters) {
71        printf("meters sign is :%s:\n",getUnitsName(meters));
72    }
73
74    if (centimeters) {
75        cm_exp = getExponent(centimeters);
76        cm_basis = getBasis(centimeters);
77
78        printf("centimeters sign is :%s:\n",getUnits(centimeters));
79        printf("cm_exp is :%f:\n",cm_exp);
80
81        if (cm_basis) {
82            printf("cm_basis sign is :%s:\n",getUnitsName(cm_basis));
83        }
84        else {
85            printf("cm_basis is NULL\n");
86        }
87
88    }
89
90    nanometers = find("nm");
91
92    if (nanometers) {
93
94        nm_conv = convert_double_result(nanometers,meters,1.0e9,&result);
95        printf("1.0e9 nm = %f m\tresult = %d\n",nm_conv,result);
96
97        nm_conv = convert_double(nanometers,meters,1.0e9);
98        printf("1.0e9 nm = %f m\n",nm_conv);
99
100        showUnits = 1;
101        nm_conv_str = convert_str(nanometers,meters,1.588e9,showUnits);
102        printf("1.588e9 nm = %s\n",nm_conv_str);
103
104        showUnits = 0;
105        nm_conv_str = convert_str(nanometers,meters,1.588e9,showUnits);
106        printf("1.588e9 nm = %s\n",nm_conv_str);
107    }
108    else {
109        printf("nanometers is NULL\n");
110    }
111
112    if (meters && angstrom && centimeters) {
113        value = convert_double_result(angstrom,meters,1.0,&result);
114        printf("1 angstrom = %e meters\n",value);
115
116        value = convert_double_result(centimeters,angstrom,1e-8,&result);
117        printf("1.0e-8 centimeter = %f angstroms\n",value);
118    }
119    else {
120        printf("meters or angstrom or centimeters is NULL\n");
121    }
122
123
124    if (fahrenheit && celcius) {
125        value = convert_double_result(fahrenheit,celcius,72,&result);
126        printf("72 degrees fahrenheit = %f degrees celcius\n",value);
127   
128        value = convert_double_result(celcius,fahrenheit,value,&result);
129        printf("22.222 degrees celcius = %f degrees fahrenheit\n",value);
130    }
131    else {
132        printf("fahrenheit or celcius is NULL\n");
133    }
134       
135    if (celcius && kelvin) {
136        value = convert_double_result(celcius,kelvin,20,&result);
137        printf("20 degrees celcius = %f kelvin\n",value);
138
139        value = convert_double_result(kelvin,celcius,300,&result);
140        printf("300 kelvin = %f degrees celcius\n", value);
141    }
142    else {
143        printf("celcius or kelvin is NULL\n");
144    }
145
146    return 0;
147}
Note: See TracBrowser for help on using the repository browser.