|
| 1 | +/* |
| 2 | +Name: geoszbtoyxh.c |
| 3 | +Version: 1.5 |
| 4 | +Date: 2018-05-24 |
| 5 | +Author: zvezdochiot (https://github.com/zvezdochiot) |
| 6 | +* |
| 7 | +build: |
| 8 | +$ gcc -o geoszzbtoyxh geosvbtoyxh.c -lm |
| 9 | +sample: |
| 10 | +$ ./geoszbtoyxh doc/szb.dat yxh.dat |
| 11 | +* |
| 12 | +file: |
| 13 | +input file doc/szb.dat: |
| 14 | +* |
| 15 | +OKD-4 8.605 74.08666667 234.38916667 1 |
| 16 | +OKD-5 8.869 81.18888889 254.73888889 1 |
| 17 | +OKD-K3-1 3.670 82.43944444 339.05361111 1 |
| 18 | +OKD-K3-4 3.690 70.66833333 161.16 1 |
| 19 | +OKD-K5P 3.938 71.95527778 137.52222222 1 |
| 20 | +OKD-K7L 4.685 83.96444444 17.82444444 1 |
| 21 | +OKD-K7L 4.684 276.03361111 197.82722222 2 |
| 22 | +OKD-K5P 3.939 288.04361111 317.52472222 2 |
| 23 | +OKD-K3-4 3.691 289.32972222 341.16111111 2 |
| 24 | +OKD-K3-1 3.671 277.55583333 159.05805556 2 |
| 25 | +OKD-5 8.869 278.80944444 74.74055556 2 |
| 26 | +OKD-4 8.604 285.91444444 54.38972222 2 |
| 27 | +OKD-11 3.889 71.6025 313.60777778 1 |
| 28 | +OKD-12 3.889 288.39138889 133.60805556 1 |
| 29 | +* |
| 30 | +output file yxh.dat: |
| 31 | +* |
| 32 | +OKD-4 -6.7277 -4.8185 2.3593 |
| 33 | +OKD-5 -8.4553 -2.3069 1.3585 |
| 34 | +OKD-K3-1 -1.3006 3.3977 0.4829 |
| 35 | +OKD-K3-4 1.1244 -3.2954 1.2215 |
| 36 | +OKD-K5P 2.5285 -2.7616 1.2198 |
| 37 | +OKD-K7L 1.4261 4.4354 0.4926 |
| 38 | +OKD-K7L 1.4261 4.4344 0.4923 |
| 39 | +OKD-K5P 2.5291 -2.7624 1.2201 |
| 40 | +OKD-K3-4 1.1247 -3.2964 1.2217 |
| 41 | +OKD-K3-1 -1.3007 3.3987 0.4827 |
| 42 | +OKD-5 -8.4554 -2.3067 1.3583 |
| 43 | +OKD-4 -6.7269 -4.8178 2.3592 |
| 44 | +OKD-11 -2.6720 2.5452 1.2274 |
| 45 | +OKD-12 -2.6721 2.5453 1.2270 |
| 46 | +* |
| 47 | +*/ |
| 48 | + |
| 49 | +#include <stdio.h> |
| 50 | +#include <stdlib.h> |
| 51 | +#include <math.h> |
| 52 | +#include <unistd.h> |
| 53 | + |
| 54 | +#define PNAME "GeoSZBtoYXH" |
| 55 | +#define PVERSION "1.5" |
| 56 | + |
| 57 | +void geoszbtoyxhtitle() |
| 58 | +{ |
| 59 | + printf("%s %s\n", PNAME, PVERSION); |
| 60 | +} |
| 61 | + |
| 62 | +void geoszbtoyxhusage() |
| 63 | +{ |
| 64 | + printf("usage: geoszbtoyxh [option] input-file report-file\n"); |
| 65 | + printf("options:\n"); |
| 66 | + printf(" -h this help\n"); |
| 67 | + printf("\n"); |
| 68 | + printf("input-file(sample):\n"); |
| 69 | + printf(" OKD-4 8.605 74.08666667 234.38916667 1\n"); |
| 70 | + printf(" OKD-5 8.869 81.18888889 254.73888889 1\n"); |
| 71 | + printf(" OKD-K3-1 3.670 82.43944444 339.05361111 1\n"); |
| 72 | + printf(" OKD-K3-4 3.690 70.66833333 161.16 1\n"); |
| 73 | + printf(" OKD-K5P 3.938 71.95527778 137.52222222 1\n"); |
| 74 | + printf(" OKD-K7L 4.685 83.96444444 17.82444444 1\n"); |
| 75 | + printf(" OKD-K7L 4.684 276.03361111 197.82722222 2\n"); |
| 76 | + printf(" OKD-K5P 3.939 288.04361111 317.52472222 2\n"); |
| 77 | + printf(" OKD-K3-4 3.691 289.32972222 341.16111111 2\n"); |
| 78 | + printf(" OKD-K3-1 3.671 277.55583333 159.05805556 2\n"); |
| 79 | + printf(" OKD-5 8.869 278.80944444 74.74055556 2\n"); |
| 80 | + printf(" OKD-4 8.604 285.91444444 54.38972222 2\n"); |
| 81 | + printf(" OKD-11 3.889 71.6025 313.60777778 1\n"); |
| 82 | + printf(" OKD-12 3.889 288.39138889 133.60805556 1\n"); |
| 83 | + printf("\n"); |
| 84 | + printf("report-file(sample):\n"); |
| 85 | + printf(" OKD-4 -6.7277 -4.8185 2.3593\n"); |
| 86 | + printf(" OKD-5 -8.4553 -2.3069 1.3585\n"); |
| 87 | + printf(" OKD-K3-1 -1.3006 3.3977 0.4829\n"); |
| 88 | + printf(" OKD-K3-4 1.1244 -3.2954 1.2215\n"); |
| 89 | + printf(" OKD-K5P 2.5285 -2.7616 1.2198\n"); |
| 90 | + printf(" OKD-K7L 1.4261 4.4354 0.4926\n"); |
| 91 | + printf(" OKD-K7L 1.4261 4.4344 0.4923\n"); |
| 92 | + printf(" OKD-K5P 2.5291 -2.7624 1.2201\n"); |
| 93 | + printf(" OKD-K3-4 1.1247 -3.2964 1.2217\n"); |
| 94 | + printf(" OKD-K3-1 -1.3007 3.3987 0.4827\n"); |
| 95 | + printf(" OKD-5 -8.4554 -2.3067 1.3583\n"); |
| 96 | + printf(" OKD-4 -6.7269 -4.8178 2.3592\n"); |
| 97 | + printf(" OKD-11 -2.6720 2.5452 1.2274\n"); |
| 98 | + printf(" OKD-12 -2.6721 2.5453 1.2270\n"); |
| 99 | +} |
| 100 | + |
| 101 | +int main(int argc, char *argv[]) |
| 102 | +{ |
| 103 | + char buf[1024], name[32]; |
| 104 | + double x[3], y[3], z[3]; |
| 105 | + int np, cn; |
| 106 | + FILE *fp0, *fp1; |
| 107 | + |
| 108 | + int opt; |
| 109 | + int fhelp = 0; |
| 110 | + while ((opt = getopt(argc, argv, ":h")) != -1) |
| 111 | + { |
| 112 | + switch(opt) |
| 113 | + { |
| 114 | + case 'h': |
| 115 | + fhelp = 1; |
| 116 | + break; |
| 117 | + case ':': |
| 118 | + printf("option needs a value\n"); |
| 119 | + break; |
| 120 | + case '?': |
| 121 | + printf("unknown option: %c\n", optopt); |
| 122 | + break; |
| 123 | + } |
| 124 | + } |
| 125 | + |
| 126 | + geoszbtoyxhtitle(); |
| 127 | + |
| 128 | + if ((optind + 2 > argc) || (fhelp > 0)) |
| 129 | + { |
| 130 | + geoszbtoyxhusage(); |
| 131 | + exit(0); |
| 132 | + } |
| 133 | + |
| 134 | + if ((fp0 = fopen(argv[optind], "r")) == NULL) |
| 135 | + { |
| 136 | + printf("can't open %s\n", argv[1]); |
| 137 | + exit(EXIT_FAILURE); |
| 138 | + } |
| 139 | + if ((fp1 = fopen(argv[optind + 1], "w")) == NULL) |
| 140 | + { |
| 141 | + printf("can't create %s\n", argv[2]); |
| 142 | + exit(EXIT_FAILURE); |
| 143 | + } |
| 144 | + |
| 145 | + while (fgets(buf, 1024, fp0) != NULL) |
| 146 | + { |
| 147 | + cn = 0; |
| 148 | + np = sscanf(buf, "%s %lf %lf %lf %d %lf %lf %lf ", name, &x[0], &x[1], &x[2], &cn, &z[0], &z[1], &z[2]); |
| 149 | + if (cn == 2) |
| 150 | + { |
| 151 | + x[1] = x[1] - 270; |
| 152 | + x[2] -= 180; |
| 153 | + if (x[2] < 0) {x[2] += 360;} |
| 154 | + } else { |
| 155 | + x[1] = 90 - x[1];; |
| 156 | + } |
| 157 | + x[1] *= M_PI; |
| 158 | + x[1] /= 180.0; |
| 159 | + x[2] *= M_PI; |
| 160 | + x[2] /= 180.0; |
| 161 | + y[2] = x[0] * sin(x[1]); |
| 162 | + x[0] *= cos(x[1]); |
| 163 | + y[0] = x[0] * sin(x[2]); |
| 164 | + y[1] = x[0] * cos(x[2]); |
| 165 | + if (np >= 8) |
| 166 | + { |
| 167 | + fprintf(fp1, "%s %.4f %.4f %.4f %.4f %.4f %.4f 1\n", name, y[0], y[1], y[2], z[0], z[1], z[2]); |
| 168 | + } else { |
| 169 | + fprintf(fp1, "%s %.4f %.4f %.4f\n", name, y[0], y[1], y[2]); |
| 170 | + } |
| 171 | + } |
| 172 | + fclose(fp1); |
| 173 | + fclose(fp0); |
| 174 | + |
| 175 | + return 0; |
| 176 | +} |
0 commit comments