質問編集履歴

1

コードを追加しました

2020/12/31 06:42

投稿

seikin_tv_love
seikin_tv_love

スコア3

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,348 @@
1
+ ```c
2
+
3
+ #include <stdio.h>
4
+
5
+ #include <stdlib.h>
6
+
7
+ #include <string.h>
8
+
9
+ #include <math.h>
10
+
11
+
12
+
13
+
14
+
15
+ /*---------------------------*/
16
+
17
+ /* Conventional Routines */
18
+
19
+ /*---------------------------*/
20
+
21
+
22
+
23
+ #define MxGEN 9
24
+
25
+ #define RAD (180./3.14159265359)
26
+
27
+ #define MxMOD 19
28
+
29
+ #define MxELM ((MxMOD+1)*(MxMOD+1)-1)
30
+
31
+ #define MxCOL 50
32
+
33
+ #define LLINE (MxCOL*9 + 10)
34
+
35
+
36
+
37
+ void gigrf(int gen, double year)
38
+
39
+ { int maxod, i, n, m, l, k, ncol, nlin;
40
+
41
+ double y1, y2, yr1, yr2, dy;
42
+
43
+ double tzero, dmy[3], cb[MxELM], cv[MxELM];
44
+
45
+ char path[]="/home/SHARE/data/IGRFCOEF/igrf00.coef";
46
+
47
+ char file[]="/home/SHARE/data/IGRFCOEF/igrf00.coef";
48
+
49
+ char *pstr, *line, buf[LLINE];
50
+
51
+ FILE *fp;
52
+
53
+ if ((gen<1) || (MxGEN<gen))
54
+
55
+ { fprintf(stderr, "gigrf: unknown NGEN = %d\n", gen); exit(1); }
56
+
57
+ strcpy(file, path);
58
+
59
+ if ((pstr=strstr(file,"00")) == NULL)
60
+
61
+ { fprintf(stderr, "gigrf: filename invalid\n"); exit(1); }
62
+
63
+ sprintf(buf, "%02d", gen); strncpy(pstr, buf, 2);
64
+
65
+ if ((fp=fopen(file,"r")) == NULL)
66
+
67
+ { fprintf(stderr, "gigrf: file not found\n"); exit(1); }
68
+
69
+ if (fgets(buf,LLINE,fp) == NULL)
70
+
71
+ { fprintf(stderr, "gigrf: file empty\n"); exit(1); }
72
+
73
+ if (sscanf(buf,"%d%d%lf%lf",&maxod,&ncol,&y1,&y2) != 4)
74
+
75
+ { fprintf(stderr, "gigrf: Line-1 format error\n"); exit(1); }
76
+
77
+ if ((maxod<8) || (maxod>MxMOD) || (ncol<2) || (ncol>MxCOL))
78
+
79
+ { fprintf(stderr, "gigrf: Line-1 invalid\n"); exit(1); }
80
+
81
+ nlin = (maxod+1)*(maxod+1) - 1;
82
+
83
+ if ((year<y1) || (year>y2))
84
+
85
+ fprintf(stderr, "gigrf: IGRF-%02d not defined for %9.3lf\n", gen,year);
86
+
87
+ if (fgets(buf,LLINE,fp) == NULL)
88
+
89
+ { fprintf(stderr, "gigrf: EOF before Line-2\n"); exit(1); }
90
+
91
+ line = &buf[1];
92
+
93
+ if (sscanf(line,"%*c%*d%*d%lf%n",&yr2,&n) == EOF)
94
+
95
+ { fprintf(stderr, "gigrf: Line-2 invalid\n"); exit(1); }
96
+
97
+ for (l=2; l<ncol; l++) {
98
+
99
+ line += n; yr1 = yr2;
100
+
101
+ if (sscanf(line,"%lf%n",&yr2,&n) == EOF)
102
+
103
+ { fprintf(stderr, "gigrf: Line-2 short\n"); exit(1); }
104
+
105
+ if (year < yr2) break;
106
+
107
+ }
108
+
109
+ for (i=0; i<nlin; i++) {
110
+
111
+ if (fgets(buf,LLINE,fp) == NULL)
112
+
113
+ { fprintf(stderr, "gigrf: EOF before Line-%d\n", i+3); exit(1); }
114
+
115
+ line = &buf[0];
116
+
117
+ if (sscanf(line,"%*c%*d%*d%n",&n) == EOF)
118
+
119
+ { fprintf(stderr, "gigrf: Line-%d invalid\n", i+3); exit(1); }
120
+
121
+ for (m=2; m<l; m++) {
122
+
123
+ line += n;
124
+
125
+ if (sscanf(line,"%*lf%n",&n) == EOF)
126
+
127
+ { fprintf(stderr, "gigrf: Line-%d short\n", i+3); exit(1); }
128
+
129
+ }
130
+
131
+ line += n;
132
+
133
+ if (sscanf(line,"%lf%lf",&cb[i],&cv[i]) != 2)
134
+
135
+ { fprintf(stderr, "gigrf: Line-%d short\n", i+3); exit(1); }
136
+
137
+ }
138
+
139
+ if (l == ncol) tzero = yr2;
140
+
141
+ else {
142
+
143
+ tzero = yr1; yr2 -= yr1;
144
+
145
+ for (i=0; i<nlin; i++) cv[i] = (cv[i]-cb[i])/yr2;
146
+
147
+ }
148
+
149
+ k = 0;
150
+
151
+ for (i=0,n=1; n<=maxod; n++) {
152
+
153
+ vgh[0][n]=cb[i]; vght[0][n]=cv[i]; i++;
154
+
155
+ if ((cb[i]!=0.) || (cv[i]!=0.)) k = n;
156
+
157
+ for (m=1; m<=n; m++) {
158
+
159
+ vgh[m][n]=cb[i]; vght[m][n]=cv[i]; i++;
160
+
161
+ if ((cb[i]!=0.) || (cv[i]!=0.)) k = n;
162
+
163
+ vgh[n][m-1]=cb[i]; vght[n][m-1]=cv[i]; i++;
164
+
165
+ if ((cb[i]!=0.) || (cv[i]!=0.)) k = n;
166
+
167
+ }
168
+
169
+ }
170
+
171
+ maxod = k;
172
+
173
+ field(6378.16, 298.25, 6371.2, maxod);
174
+
175
+ tcoef(vgh, vght, tzero, 0, dmy); tyear(year);
176
+
177
+ }
178
+
179
+
180
+
181
+ void igrfc(double fido, double fkeido, double hght, double *tf)
182
+
183
+ { double fx, fy, fz;
184
+
185
+ mfldg(fido, fkeido, hght/1000., &fx, &fy, &fz, tf);
186
+
187
+ }
188
+
189
+
190
+
191
+ void igrfm(double fm[6])
192
+
193
+ { double gx, gy, gz, h, dip, dec;
194
+
195
+ gcomp(&gx, &gy, &gz);
196
+
197
+ h=sqrt(gx*gx+gy*gy); dip=atan2(gz,h); dec=atan2(gy,gx);
198
+
199
+ fm[0]=gx; fm[1]=gy; fm[2]=gz; fm[3]=h; fm[4]=dip*RAD; fm[5]=dec*RAD;
200
+
201
+ }
202
+
203
+
204
+
205
+
206
+
207
+ void sigrf(double year)
208
+
209
+ { int maxod, i, n, m, l;
210
+
211
+ double tzero, dmy[3];
212
+
213
+ l=(int)(year-1970.)/5; if (l < 0) l=0; else if (l >= 7) l=6;
214
+
215
+ if (l < 2) maxod=8; else maxod=10;
216
+
217
+ tzero=(double)(l*5 + 1970); if (l==0) tzero=1965.;
218
+
219
+ if ((year<1955.) || (year>2005.))
220
+
221
+ fprintf(stderr, "sigrf: IGRF not available for %8.3lf\n", year);
222
+
223
+ for (i=0,n=1; n<=maxod; n++) {
224
+
225
+ vgh[0][n]=rf[l][i];
226
+
227
+ if (n<=8) vght[0][n]=sv[l][i]; else vght[0][n]=0.;
228
+
229
+ i++;
230
+
231
+ for (m=1; m<=n; m++) {
232
+
233
+ vgh[m][n]=rf[l][i];
234
+
235
+ if (n<=8) vght[m][n]=sv[l][i]; else vght[m][n]=0.;
236
+
237
+ i++;
238
+
239
+ vgh[n][m-1]=rf[l][i];
240
+
241
+ if (n<=8) vght[n][m-1]=sv[l][i]; else vght[n][m-1]=0.;
242
+
243
+ i++;
244
+
245
+ }
246
+
247
+ }
248
+
249
+ field(6378.16, 298.25, 6371.2, maxod);
250
+
251
+ tcoef(vgh, vght, tzero, 0, dmy); tyear(year);
252
+
253
+ }
254
+
255
+
256
+
257
+ void sdgrf(double year)
258
+
259
+ { int i, n, m, l;
260
+
261
+ double dmy[3];
262
+
263
+ l=(int)(year-1945.)/5; if (l < 0) l=0; else if (l >= 9) l=8;
264
+
265
+ if ((year<1945.) || (year>1990.))
266
+
267
+ fprintf(stderr, "sdgrf: DGRF not available for %8.3lf\n", year);
268
+
269
+ for (i=0,n=1; n<=10; n++) {
270
+
271
+ vgh[0][n]=df[l][i]; vght[0][n]=(df[l+1][i]-df[l][i])/5.; i++;
272
+
273
+ for (m=1; m<=n; m++) {
274
+
275
+ vgh[m][n]=df[l][i]; vght[m][n]=(df[l+1][i]-df[l][i])/5.; i++;
276
+
277
+ vgh[n][m-1]=df[l][i]; vght[n][m-1]=(df[l+1][i]-df[l][i])/5.; i++;
278
+
279
+ }
280
+
281
+ }
282
+
283
+ field(6378.16, 298.25, 6371.2, 10);
284
+
285
+ tcoef(vgh, vght, (double)(1945+l*5), 0, dmy); tyear(year);
286
+
287
+ }
288
+
289
+
290
+
291
+ void spgrf(double year)
292
+
293
+ { int i, n, m, l;
294
+
295
+ double dmy[3];
296
+
297
+ l=(int)(year-1945.)/5; if (l < 6) l=6; else if (l >= 10) l=9;
298
+
299
+ if ((year<1975.) || (year>1995.))
300
+
301
+ fprintf(stderr, "spgrf: PGRF not available for %8.3lf\n", year);
302
+
303
+ for (i=0,n=1; n<=10; n++) {
304
+
305
+ vgh[0][n]=df[l][i]; vght[0][n]=(rf[l-4][i]-df[l][i])/5.; i++;
306
+
307
+ for (m=1; m<=n; m++) {
308
+
309
+ vgh[m][n]=df[l][i]; vght[m][n]=(rf[l-4][i]-df[l][i])/5.; i++;
310
+
311
+ vgh[n][m-1]=df[l][i]; vght[n][m-1]=(rf[l-4][i]-df[l][i])/5.; i++;
312
+
313
+ }
314
+
315
+ }
316
+
317
+ field(6378.16, 298.25, 6371.2, 10);
318
+
319
+ tcoef(vgh, vght, (double)(1945+l*5), 0, dmy); tyear(year);
320
+
321
+ }
322
+
323
+
324
+
325
+ void gigrf_(int *gen, float *year) { gigrf(*gen, (double)*year); }
326
+
327
+ void igrfc_(float *fi, float *fk, float *h, float *f)
328
+
329
+ { double df; igrfc((double)*fi,(double)*fk,(double)*h,&df); *f=df; }
330
+
331
+ void igrfm_(float fm[6])
332
+
333
+ { double dfm[6]; int i; igrfm(dfm); for (i=0; i<6; i++) fm[i]=dfm[i]; }
334
+
335
+ void sigrf_(float *year) { sigrf((double)*year); }
336
+
337
+ void sdgrf_(float *year) { sdgrf((double)*year); }
338
+
339
+ void spgrf_(float *year) { spgrf((double)*year); }
340
+
341
+
342
+
343
+ コード
344
+
1
- ### 前提・実現したいこと
345
+ ```### 前提・実現したいこと
2
346
 
3
347
  igrfによる磁場を計算するプログラムを学習しています
4
348