-
Notifications
You must be signed in to change notification settings - Fork 79
/
42init.c
4126 lines (3873 loc) · 160 KB
/
42init.c
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
/* This file is distributed with 42, */
/* the (mostly harmless) spacecraft dynamics simulation */
/* created by Eric Stoneking of NASA Goddard Space Flight Center */
/* Copyright 2010 United States Government */
/* as represented by the Administrator */
/* of the National Aeronautics and Space Administration. */
/* No copyright is claimed in the United States */
/* under Title 17, U.S. Code. */
/* All Other Rights Reserved. */
#include "42.h"
#include <ctype.h>
/* #ifdef __cplusplus
** namespace _42 {
** using namespace Kit;
** #endif
*/
/**********************************************************************/
long DecodeString(char *s)
{
unsigned long i;
for(i=0;i<strlen(s);i++) s[i] = toupper(s[i]);
if (!strcmp(s,"FALSE")) return FALSE;
else if (!strcmp(s,"TRUE")) return TRUE;
else if (!strcmp(s,"OFF")) return OFF;
else if (!strcmp(s,"ON")) return ON;
else if (!strcmp(s,"FAST")) return FAST_TIME;
else if (!strcmp(s,"REAL")) return REAL_TIME;
else if (!strcmp(s,"EXTERNAL")) return EXTERNAL_TIME;
else if (!strcmp(s,"NOS3")) return NOS3_TIME;
else if (!strcmp(s,"SOL")) return SOL;
else if (!strcmp(s,"MERCURY")) return MERCURY;
else if (!strcmp(s,"VENUS")) return VENUS;
else if (!strcmp(s,"EARTH")) return EARTH;
else if (!strcmp(s,"MARS")) return MARS;
else if (!strcmp(s,"JUPITER")) return JUPITER;
else if (!strcmp(s,"SATURN")) return SATURN;
else if (!strcmp(s,"URANUS")) return URANUS;
else if (!strcmp(s,"NEPTUNE")) return NEPTUNE;
else if (!strcmp(s,"PLUTO")) return PLUTO;
else if (!strcmp(s,"LUNA")) return LUNA;
else if (!strcmp(s,"KEP")) return INP_KEPLER;
else if (!strcmp(s,"RV")) return INP_POSVEL;
else if (!strcmp(s,"FILE")) return INP_FILE;
else if (!strcmp(s,"TLE")) return INP_TLE;
else if (!strcmp(s,"TRV")) return INP_TRV;
else if (!strcmp(s,"PA")) return TRUE;
else if (!strcmp(s,"AE")) return FALSE;
else if (!strcmp(s,"POSW")) return TRUE;
else if (!strcmp(s,"LLA")) return FALSE;
else if (!strcmp(s,"POS")) return POSITIVE;
else if (!strcmp(s,"NEG")) return NEGATIVE;
else if (!strcmp(s,"CM")) return TRUE;
else if (!strcmp(s,"ORIGIN")) return FALSE;
else if (!strcmp(s,"CENTRAL")) return ORB_CENTRAL;
else if (!strcmp(s,"THREE_BODY")) return ORB_THREE_BODY;
else if (!strcmp(s,"ZERO")) return ORB_ZERO;
else if (!strcmp(s,"FLIGHT")) return ORB_FLIGHT;
else if (!strcmp(s,"EARTHMOON")) return EARTHMOON;
else if (!strcmp(s,"SUNEARTH")) return SUNEARTH;
else if (!strcmp(s,"SUNJUPITER")) return SUNJUPITER;
else if (!strcmp(s,"MODES")) return INP_MODES;
else if (!strcmp(s,"XYZ")) return INP_XYZ;
else if (!strcmp(s,"SPLINE")) return INP_SPLINE;
else if (!strcmp(s,"L1")) return LAGPT_L1;
else if (!strcmp(s,"L2")) return LAGPT_L2;
else if (!strcmp(s,"L3")) return LAGPT_L3;
else if (!strcmp(s,"L4")) return LAGPT_L4;
else if (!strcmp(s,"L5")) return LAGPT_L5;
else if (!strcmp(s,"CW")) return DIR_CW;
else if (!strcmp(s,"CCW")) return DIR_CCW;
else if (!strcmp(s,"NONE")) return NONE;
else if (!strcmp(s,"DIPOLE")) return DIPOLE;
else if (!strcmp(s,"IGRF")) return IGRF;
else if (!strcmp(s,"SPHERICAL")) return 1;
else if (!strcmp(s,"GIMBAL")) return 0;
else if (!strcmp(s,"X_AXIS")) return X_AXIS;
else if (!strcmp(s,"Y_AXIS")) return Y_AXIS;
else if (!strcmp(s,"Z_AXIS")) return Z_AXIS;
else if (!strcmp(s,"POS_X")) return POS_X;
else if (!strcmp(s,"POS_Y")) return POS_Y;
else if (!strcmp(s,"POS_Z")) return POS_Z;
else if (!strcmp(s,"NEG_X")) return NEG_X;
else if (!strcmp(s,"NEG_Y")) return NEG_Y;
else if (!strcmp(s,"NEG_Z")) return NEG_Z;
else if (!strcmp(s,"REFORB")) return TARGET_REFORB;
else if (!strcmp(s,"FRM")) return TARGET_FRM;
else if (!strcmp(s,"SC")) return TARGET_SC;
else if (!strcmp(s,"BODY")) return TARGET_BODY;
else if (!strcmp(s,"TRACK_HOST")) return TRACK_HOST;
else if (!strcmp(s,"TRACK_TARGET")) return TRACK_TARGET;
else if (!strcmp(s,"FIXED_IN_HOST")) return FIXED_IN_HOST;
else if (!strcmp(s,"DOWN")) return VIEW_DOWN;
else if (!strcmp(s,"REAR_LEFT")) return VIEW_REAR_LEFT;
else if (!strcmp(s,"REAR")) return VIEW_REAR;
else if (!strcmp(s,"REAR_RIGHT")) return VIEW_REAR_RIGHT;
else if (!strcmp(s,"LEFT")) return VIEW_LEFT;
else if (!strcmp(s,"UP")) return VIEW_UP;
else if (!strcmp(s,"RIGHT")) return VIEW_RIGHT;
else if (!strcmp(s,"FRONT_LEFT")) return VIEW_FRONT_LEFT;
else if (!strcmp(s,"FRONT")) return VIEW_FRONT;
else if (!strcmp(s,"FRONT_RIGHT")) return VIEW_FRONT_RIGHT;
else if (!strcmp(s,"WIREFRAME")) return FOV_WIREFRAME;
else if (!strcmp(s,"SOLID")) return FOV_SOLID;
else if (!strcmp(s,"VECTOR")) return FOV_VECTOR;
else if (!strcmp(s,"PLANE")) return FOV_PLANE;
else if (!strcmp(s,"REFPT_CM")) return REFPT_CM;
else if (!strcmp(s,"REFPT_JOINT")) return REFPT_JOINT;
else if (!strcmp(s,"LAGDOF_MODES")) return LAGDOF_MODES;
else if (!strcmp(s,"LAGDOF_COWELL")) return LAGDOF_COWELL;
else if (!strcmp(s,"LAGDOF_SPLINE")) return LAGDOF_SPLINE;
else if (!strcmp(s,"STEADY")) return ROTDOF_STEADY;
else if (!strcmp(s,"KIN_JOINT")) return ROTDOF_KIN_JOINT;
else if (!strcmp(s,"DYN_JOINT")) return ROTDOF_DYN_JOINT;
else if (!strcmp(s,"FIXED")) return ORBDOF_FIXED;
else if (!strcmp(s,"EULER_HILL")) return ORBDOF_EULER_HILL;
else if (!strcmp(s,"ENCKE")) return ORBDOF_ENCKE;
else if (!strcmp(s,"COWELL")) return ORBDOF_COWELL;
else if (!strcmp(s,"PASSIVE_FSW")) return PASSIVE_FSW;
else if (!strcmp(s,"PROTOTYPE_FSW")) return PROTOTYPE_FSW;
else if (!strcmp(s,"AD_HOC_FSW")) return AD_HOC_FSW;
else if (!strcmp(s,"SPINNER_FSW")) return SPINNER_FSW;
else if (!strcmp(s,"MOMBIAS_FSW")) return MOMBIAS_FSW;
else if (!strcmp(s,"THREE_AXIS_FSW")) return THREE_AXIS_FSW;
else if (!strcmp(s,"ISS_FSW")) return ISS_FSW;
else if (!strcmp(s,"CMG_FSW")) return CMG_FSW;
else if (!strcmp(s,"THR_FSW")) return THR_FSW;
else if (!strcmp(s,"CFS_FSW")) return CFS_FSW;
else if (!strcmp(s,"PHOBOS")) return PHOBOS;
else if (!strcmp(s,"DEIMOS")) return DEIMOS;
else if (!strcmp(s,"IO")) return IO;
else if (!strcmp(s,"EUROPA")) return EUROPA;
else if (!strcmp(s,"GANYMEDE")) return GANYMEDE;
else if (!strcmp(s,"CALLISTO")) return CALLISTO;
else if (!strcmp(s,"AMALTHEA")) return AMALTHEA;
else if (!strcmp(s,"HIMALIA")) return HIMALIA;
else if (!strcmp(s,"ELARA")) return ELARA;
else if (!strcmp(s,"PASIPHAE")) return PASIPHAE;
else if (!strcmp(s,"SINOPE")) return SINOPE;
else if (!strcmp(s,"LYSITHEA")) return LYSITHEA;
else if (!strcmp(s,"CARME")) return CARME;
else if (!strcmp(s,"ANANKE")) return ANANKE;
else if (!strcmp(s,"LEDA")) return LEDA;
else if (!strcmp(s,"THEBE")) return THEBE;
else if (!strcmp(s,"ADRASTEA")) return ADRASTEA;
else if (!strcmp(s,"METIS")) return METIS;
else if (!strcmp(s,"MIMAS")) return MIMAS;
else if (!strcmp(s,"ENCELADUS")) return ENCELADUS;
else if (!strcmp(s,"TETHYS")) return TETHYS;
else if (!strcmp(s,"DIONE")) return DIONE;
else if (!strcmp(s,"RHEA")) return RHEA;
else if (!strcmp(s,"TITAN")) return TITAN;
else if (!strcmp(s,"HYPERION")) return HYPERION;
else if (!strcmp(s,"IAPETUS")) return IAPETUS;
else if (!strcmp(s,"PHOEBE")) return PHOEBE;
else if (!strcmp(s,"JANUS")) return JANUS;
else if (!strcmp(s,"EPIMETHEUS")) return EPIMETHEUS;
else if (!strcmp(s,"HELENE")) return HELENE;
else if (!strcmp(s,"TELESTO")) return TELESTO;
else if (!strcmp(s,"CALYPSO")) return CALYPSO;
else if (!strcmp(s,"ATLAS")) return ATLAS;
else if (!strcmp(s,"PROMETHEUS")) return PROMETHEUS;
else if (!strcmp(s,"PANDORA")) return PANDORA;
else if (!strcmp(s,"PAN")) return PAN;
else if (!strcmp(s,"ARIEL")) return ARIEL;
else if (!strcmp(s,"UMBRIEL")) return UMBRIEL;
else if (!strcmp(s,"TITANIA")) return TITANIA;
else if (!strcmp(s,"OBERON")) return OBERON;
else if (!strcmp(s,"MIRANDA")) return MIRANDA;
else if (!strcmp(s,"TRITON")) return TRITON;
else if (!strcmp(s,"NERIED")) return NERIED;
else if (!strcmp(s,"CHARON")) return CHARON;
else if (sscanf(s,"MINORBODY_%ld",&i) == 1) return(55+i);
else if (!strcmp(s,"SUN")) return SUN;
else if (!strcmp(s,"PLANET")) return PLANET;
else if (!strcmp(s,"MOON")) return MOON;
else if (!strcmp(s,"ASTEROID")) return ASTEROID;
else if (!strcmp(s,"COMET")) return COMET;
else if (!strcmp(s,"SIDE")) return VIEW_SIDE;
else if (!strcmp(s,"TOP")) return VIEW_TOP;
else if (!strcmp(s,"TWOSIGMA_KP")) return TWOSIGMA_KP;
else if (!strcmp(s,"NOMINAL")) return NOMINAL;
else if (!strcmp(s,"USER_DEFINED")) return USER_DEFINED;
else if (!strcmp(s,"TX")) return IPC_TX;
else if (!strcmp(s,"RX")) return IPC_RX;
else if (!strcmp(s,"TXRX")) return IPC_TXRX;
else if (!strcmp(s,"ACS")) return IPC_ACS;
else if (!strcmp(s,"WRITEFILE")) return IPC_WRITEFILE;
else if (!strcmp(s,"READFILE")) return IPC_READFILE;
else if (!strcmp(s,"SPIRENT")) return IPC_SPIRENT;
else if (!strcmp(s,"FFTB")) return IPC_FFTB;
else if (!strcmp(s,"SERVER")) return IPC_SERVER;
else if (!strcmp(s,"CLIENT")) return IPC_CLIENT;
else if (!strcmp(s,"GMSEC_CLIENT")) return IPC_GMSEC_CLIENT;
else if (!strcmp(s,"MEAN")) return EPH_MEAN;
else if (!strcmp(s,"DE430")) return EPH_DE430;
else if (!strcmp(s,"MAJOR")) return MAJOR_CONSTELL;
else if (!strcmp(s,"ZODIAC")) return ZODIAC_CONSTELL;
else if (!strcmp(s,"MINOR")) return MINOR_CONSTELL;
else {
printf("Bogus input %s in DecodeString (42init.c:%d)\n",s,__LINE__);
exit(1);
}
}
/**********************************************************************/
void EchoDyn(struct SCType *S)
{
FILE *outfile;
char OutFileName[80];
struct DynType *D;
struct BodyType *B;
struct JointType *G;
long i,j,Ib,Ig,Nf;
sprintf(OutFileName,"Dyn%02li.42",S->ID);
outfile = FileOpen(InOutPath,OutFileName,"w");
/* .. SC Structure */
fprintf(outfile,"Dynamics Check for SC[%ld]\n\n",S->ID);
fprintf(outfile,"Nb: %2li Ng: %2li\n",S->Nb,S->Ng);
fprintf(outfile,"Mass: %lf\n",S->mass);
fprintf(outfile,"cm: %lf %lf %lf\n",S->cm[0],S->cm[1],S->cm[2]);
fprintf(outfile,"I : %lf %lf %lf \n %lf %lf %lf \n %lf %lf %lf\n",
S->I[0][0],S->I[0][1],S->I[0][2],
S->I[1][0],S->I[1][1],S->I[1][2],
S->I[2][0],S->I[2][1],S->I[2][2]);
fprintf(outfile,"PosR: %lf %lf %lf\n",
S->PosR[0],S->PosR[1],S->PosR[2]);
fprintf(outfile,"VelR: %lf %lf %lf\n\n",
S->VelR[0],S->VelR[1],S->VelR[2]);
/* .. Dyn Structure */
D = &S->Dyn;
fprintf(outfile,"Dyn Structure\n-------------\n");
fprintf(outfile,"Nu: %ld Nx: %ld Nf: %ld\n",D->Nu,D->Nx,D->Nf);
for(i=0;i<D->Nu;i++) fprintf(outfile,"u[%02li]: %lf\n",i,D->u[i]);
fprintf(outfile,"\n");
for(i=0;i<D->Nx;i++) fprintf(outfile,"x[%02li]: %lf\n",i,D->x[i]);
fprintf(outfile,"\n");
for(i=0;i<D->Nf;i++) fprintf(outfile,"[%02li] uf: %lf xf: %lf\n",
i,D->uf[i],D->xf[i]);
fprintf(outfile,"\n\n");
/* .. Body Structures */
for(Ib=0;Ib<S->Nb;Ib++) {
B = &S->B[Ib];
fprintf(outfile,"Body Structure [%02li]\n-------------------\n",Ib);
fprintf(outfile,"Mass: %lf\n",B->mass);
fprintf(outfile,"cm: %lf %lf %lf\n",B->cm[0],B->cm[1],B->cm[2]);
fprintf(outfile,"c: %lf %lf %lf\n",B->c[0],B->c[1],B->c[2]);
fprintf(outfile,"I: %lf %lf %lf\n %lf %lf %lf\n %lf %lf %lf\n",
B->I[0][0],B->I[0][1],B->I[0][2],
B->I[1][0],B->I[1][1],B->I[1][2],
B->I[2][0],B->I[2][1],B->I[2][2]);
fprintf(outfile,"wn: %lf %lf %lf\n",
B->wn[0],B->wn[1],B->wn[2]);
fprintf(outfile,"qn: %lf %lf %lf %lf\n",
B->qn[0],B->qn[1],B->qn[2],B->qn[3]);
fprintf(outfile,"vn: %lf %lf %lf\n",
B->vn[0],B->vn[1],B->vn[2]);
fprintf(outfile,"pn: %lf %lf %lf\n\n",
B->pn[0],B->pn[1],B->pn[2]);
fprintf(outfile,"CN:\n");
fprintf(outfile,"%lf %lf %lf\n",
B->CN[0][0],B->CN[0][1],B->CN[0][2]);
fprintf(outfile,"%lf %lf %lf\n",
B->CN[1][0],B->CN[1][1],B->CN[1][2]);
fprintf(outfile,"%lf %lf %lf\n",
B->CN[2][0],B->CN[2][1],B->CN[2][2]);
fprintf(outfile,"Nf: %ld f0: %ld\n",B->Nf,B->f0);
fprintf(outfile,"Mf:\n");
for(i=0;i<B->Nf;i++) {
for(j=0;j<B->Nf;j++) fprintf(outfile," %lf",B->Mf[i][j]);
fprintf(outfile,"\n");
}
fprintf(outfile,"\n");
fprintf(outfile,"Kf:\n");
for(i=0;i<B->Nf;i++) {
for(j=0;j<B->Nf;j++) fprintf(outfile," %lf",B->Kf[i][j]);
fprintf(outfile,"\n");
}
fprintf(outfile,"\n");
fprintf(outfile,"Cf:\n");
for(i=0;i<B->Nf;i++) {
for(j=0;j<B->Nf;j++) fprintf(outfile," %lf",B->Cf[i][j]);
fprintf(outfile,"\n");
}
fprintf(outfile,"\n");
fprintf(outfile,"Pf:\n");
for(i=0;i<3;i++) {
for(j=0;j<B->Nf;j++) fprintf(outfile," %lf",B->Pf[i][j]);
fprintf(outfile,"\n");
}
fprintf(outfile,"\n");
fprintf(outfile,"Hf:\n");
for(i=0;i<3;i++) {
for(j=0;j<B->Nf;j++) fprintf(outfile," %lf",B->Hf[i][j]);
fprintf(outfile,"\n");
}
fprintf(outfile,"\n");
}
fprintf(outfile,"\n");
/* .. Joint Structures */
for(Ig=0;Ig<S->Ng;Ig++) {
G = &S->G[Ig];
fprintf(outfile,"Joint Structure [%02li]\n---------------\n",Ig);
fprintf(outfile,"Rotu0: %ld Rotx0: %ld\n",G->Rotu0,G->Rotx0);
fprintf(outfile,"Trnu0: %ld Trnx0: %ld\n",G->Trnu0,G->Trnx0);
fprintf(outfile,"ang: %lf %lf %lf\n",
G->Ang[0],G->Ang[1],G->Ang[2]);
fprintf(outfile,"rate: %lf %lf %lf\n",
G->AngRate[0],G->AngRate[1],G->AngRate[2]);
fprintf(outfile,"COI:\n");
fprintf(outfile,"%lf %lf %lf\n",
G->COI[0][0],G->COI[0][1],G->COI[0][2]);
fprintf(outfile,"%lf %lf %lf\n",
G->COI[1][0],G->COI[1][1],G->COI[1][2]);
fprintf(outfile,"%lf %lf %lf\n",
G->COI[2][0],G->COI[2][1],G->COI[2][2]);
fprintf(outfile,"SpringCoef: %lf %lf %lf\n",
G->RotSpringCoef[0],G->RotSpringCoef[1],G->RotSpringCoef[2]);
fprintf(outfile,"DampCoef: %lf %lf %lf\n",
G->RotDampCoef[0],G->RotDampCoef[1],G->RotDampCoef[2]);
Nf = S->B[G->Bin].Nf;
fprintf(outfile,"PSIi:\n");
for(i=0;i<3;i++) {
for(j=0;j<Nf;j++) fprintf(outfile," %lf",G->PSIi[i][j]);
fprintf(outfile,"\n");
}
fprintf(outfile,"THETAi:\n");
for(i=0;i<3;i++) {
for(j=0;j<Nf;j++) fprintf(outfile," %lf",G->THETAi[i][j]);
fprintf(outfile,"\n");
}
Nf = S->B[G->Bout].Nf;
fprintf(outfile,"PSIo:\n");
for(i=0;i<3;i++) {
for(j=0;j<Nf;j++) fprintf(outfile," %lf",G->PSIo[i][j]);
fprintf(outfile,"\n");
}
fprintf(outfile,"THETAo:\n");
for(i=0;i<3;i++) {
for(j=0;j<Nf;j++) fprintf(outfile," %lf",G->THETAo[i][j]);
fprintf(outfile,"\n");
}
fprintf(outfile,"\n\n");
}
fclose(outfile);
}
/**********************************************************************/
long LoadTRVfromFile(const char *Path, const char *TrvFileName,
const char *ElemLabel, double Time, struct OrbitType *O)
{
FILE *infile;
char line[80],response1[80],response2[80];
char Label[25];
long i,Nchar;
long Success = 0;
double EpochJD,R[3],V[3];
long EpochYear,EpochMonth,EpochDay,EpochHour,EpochMinute;
double EpochSecond;
infile=FileOpen(Path,TrvFileName,"r");
Nchar = strlen(ElemLabel);
/* Pad label to 24 characters to assure unique match */
for(i=0;i<Nchar;i++) Label[i] = ElemLabel[i];
for(i=Nchar;i<24;i++) Label[i] = ' ';
Label[24] = '\0';
while(!feof(infile) && !Success) {
fgets(line,80,infile);
if (!strncmp(line,Label,24)) {
Success = 1;
fscanf(infile,"%s %s %ld-%ld-%ld %ld:%ld:%lf\n",
response1,response2,
&EpochYear,&EpochMonth,&EpochDay,
&EpochHour,&EpochMinute,&EpochSecond);
fscanf(infile,"%lf %lf %lf\n",&R[0],&R[1],&R[2]);
fscanf(infile,"%lf %lf %lf\n",&V[0],&V[1],&V[2]);
}
}
fclose(infile);
if (Success) {
EpochJD = YMDHMS2JD(EpochYear,EpochMonth,EpochDay,
EpochHour,EpochMinute,EpochSecond);
O->Epoch = JDToAbsTime(EpochJD);
O->Regime = DecodeString(response1);
if (O->Regime == ORB_CENTRAL) {
O->World = DecodeString(response2);
O->mu = World[O->World].mu;
RV2Eph(O->Epoch,O->mu,R,V,&O->SMA,&O->ecc,&O->inc,&O->RAAN,
&O->ArgP,&O->anom,&O->tp,&O->SLR,&O->alpha,&O->rmin,
&O->MeanMotion,&O->Period);
Eph2RV(O->mu,O->SLR,O->ecc,O->inc,O->RAAN,O->ArgP,Time-O->Epoch,
O->PosN,O->VelN,&O->anom);
}
else {
O->Sys = DecodeString(response2);
O->Body1 = LagSys[O->Sys].Body1;
O->Body2 = LagSys[O->Sys].Body2;
O->mu1 = World[O->Body1].mu;
O->mu2 = World[O->Body2].mu;
O->World = O->Body1;
O->mu = O->mu1;
for(i=0;i<3;i++) {
O->PosN[i] = R[i];
O->VelN[i] = V[i];
}
/* RV2LagModes(O->Epoch,&LagSys[O->Sys],O); */
R2StableLagMode(O->Epoch,&LagSys[O->Sys],O);
LagModes2RV(Time,&LagSys[O->Sys],O,O->PosN,O->VelN);
}
}
return(Success);
}
/*********************************************************************/
void InitOrbit(struct OrbitType *O)
{
FILE *infile;
char junk[120],newline,response[120];
double Alt1,Alt2,MaxAnom;
double mu,rad;
double p[3],Ang1,Ang2,Ang3;
char FrmExpressedIn;
long Ir,i,j,k,Seq;
struct FormationType *F;
double AmpXY1,PhiXY1,SenseXY1;
double AmpXY2,PhiXY2,SenseXY2;
double AmpZ,PhiZ;
struct RegionType *R;
long InputType,UsePA,ElementType;
char ElementLabel[40];
char ElementFileName[40];
long Success;
long NodeYear,NodeMonth,NodeDay,NodeHour,NodeMin;
double NodeSec;
infile = FileOpen(InOutPath,O->FileName,"r");
/* .. Orbit Parameters */
O->Epoch = AbsTime;
fscanf(infile,"%[^\n] %[\n]",junk,&newline);
fscanf(infile,"%[^\n] %[\n]",junk,&newline);
fscanf(infile,"%s %[^\n] %[\n]",response,junk,&newline);
O->Regime = DecodeString(response);
if (O->Regime == ORB_ZERO) {
fscanf(infile,"%[^\n] %[\n]",junk,&newline);
fscanf(infile,"%s %[^\n] %[\n]",response,junk,&newline);
O->World = DecodeString(response);
if (!World[O->World].Exists) {
printf("Oops. Orbit %ld depends on a World that doesn't exist.\n",O->Tag);
exit(1);
}
O->mu = World[O->World].mu;
for(j=0;j<3;j++) {
O->PosN[j] = 0.0;
O->VelN[j] = 0.0;
for(k=0;k<3;k++) O->CLN[j][k] = 0.0;
O->CLN[j][j] = 1.0;
O->wln[j] = 0.0;
}
fscanf(infile,"%s %[^\n] %[\n]",response,junk,&newline);
O->PolyhedronGravityEnabled = DecodeString(response);
/* Skip FLIGHT, CENTRAL, THREE_BODY sections */
for(j=0;j<35;j++) fscanf(infile,"%[^\n] %[\n]",junk,&newline);
}
else if (O->Regime == ORB_FLIGHT) {
/* Skip ZERO section */
for(j=0;j<3;j++) fscanf(infile,"%[^\n] %[\n]",junk,&newline);
fscanf(infile,"%[^\n] %[\n]",junk,&newline);
fscanf(infile,"%ld %[^\n] %[\n]",&Ir,junk,&newline);
if (!Rgn[Ir].Exists) {
printf("Oops. Orbit %ld depends on a Region that doesn't exist.\n",O->Tag);
exit(1);
}
O->Region = Ir;
R = &Rgn[Ir];
O->World = R->World;
O->mu = World[O->World].mu;
for(j=0;j<3;j++) {
O->PosN[j] = R->PosN[j];
O->VelN[j] = R->VelN[j];
for(k=0;k<3;k++) O->CLN[j][k] = R->CN[j][k];
O->wln[0] = 0.0;
O->wln[1] = 0.0;
O->wln[2] = World[O->World].w;
}
fscanf(infile,"%s %[^\n] %[\n]",response,junk,&newline);
O->PolyhedronGravityEnabled = DecodeString(response);
/* Skip CENTRAL and THREE_BODY sections */
for(j=0;j<32;j++) fscanf(infile,"%[^\n] %[\n]",junk,&newline);
}
else if (O->Regime == ORB_CENTRAL) {
/* Skip ZERO and FLIGHT sections */
for(j=0;j<6;j++) fscanf(infile,"%[^\n] %[\n]",junk,&newline);
fscanf(infile,"%[^\n] %[\n]",junk,&newline);
fscanf(infile,"%s %[^\n] %[\n]",response,junk,&newline);
O->World = DecodeString(response);
if (!World[O->World].Exists) {
printf("Oops. Orbit %ld depends on a World that doesn't exist.\n",O->Tag);
exit(1);
}
fscanf(infile,"%s %[^\n] %[\n]",response,junk,&newline);
O->J2DriftEnabled = DecodeString(response);
mu = World[O->World].mu;
rad = World[O->World].rad;
O->mu=mu;
fscanf(infile,"%s %[^\n] %[\n]",response,junk,&newline);
InputType = DecodeString(response);
if (InputType == INP_KEPLER) {
fscanf(infile,"%s %[^\n] %[\n]",response,junk,&newline);
UsePA = DecodeString(response);
if (UsePA) {
fscanf(infile,"%lf %lf %[^\n] %[\n]",&Alt1,&Alt2,
junk,&newline);
if (Alt2 < Alt1) {
printf("Apoapsis below Periapsis for Orbit %ld\n",O->Tag);
exit(1);
}
fscanf(infile,"%[^\n] %[\n]",junk,&newline);
O->SMA=rad+0.5*(Alt1+Alt2)*1.0E3;
O->ecc=1.0E3*fabs(Alt1-Alt2)/(2.0*O->SMA);
O->SLR = O->SMA*(1.0-O->ecc*O->ecc);
O->alpha = 1.0/O->SMA;
O->rmin = rad+Alt1*1.0E3;
}
else {
fscanf(infile,"%[^\n] %[\n]",junk,&newline);
fscanf(infile,"%lf %lf %[^\n] %[\n]",
&Alt1,&O->ecc,junk,&newline);
O->rmin = rad+Alt1*1.0E3;
O->SLR = O->rmin*(1.0+O->ecc);
O->alpha = (1.0-O->ecc)/O->rmin;
if (O->alpha != 0.0) O->SMA = 1.0/O->alpha;
}
fscanf(infile,"%lf %[^\n] %[\n]",&O->inc,junk,&newline);
fscanf(infile,"%lf %[^\n] %[\n]",&O->RAAN,junk,&newline);
fscanf(infile,"%lf %[^\n] %[\n]",&O->ArgP,junk,&newline);
fscanf(infile,"%lf %[^\n] %[\n]",&O->anom,junk,&newline);
O->inc *= D2R;
O->RAAN *= D2R;
O->ArgP *= D2R;
O->anom *= D2R;
/* Some anomalies are unreachable for hyperbolic trajectories */
if (O->ecc > 1.0) {
MaxAnom = Pi - acos(1.0/O->ecc);
if (fabs(O->anom) > MaxAnom){
printf("True Anomaly out of range for Orbit %ld\n",O->Tag);
exit(1);
}
}
if (O->J2DriftEnabled) {
O->RAAN0 = O->RAAN;
O->ArgP0 = O->ArgP;
FindJ2DriftParms(O->mu,World[O->World].J2,World[O->World].rad,O);
O->tp = O->Epoch - TimeSincePeriapsis(O->MuPlusJ2,O->SLR,O->ecc,O->anom);
Eph2RV(O->MuPlusJ2,O->SLR,O->ecc,O->inc,
O->RAAN,O->ArgP,O->Epoch-O->tp,
O->PosN,O->VelN,&O->anom);
}
else {
O->MuPlusJ2 = O->mu;
O->RAANdot = 0.0;
O->ArgPdot = 0.0;
O->J2Fr0 = 0.0;
O->J2Fh1 = 0.0;
O->MeanMotion = sqrt(O->mu/(O->SMA*O->SMA*O->SMA));
O->Period = TwoPi/O->MeanMotion;
O->tp = O->Epoch - TimeSincePeriapsis(O->mu,O->SLR,O->ecc,O->anom);
Eph2RV(O->mu,O->SLR,O->ecc,O->inc,
O->RAAN,O->ArgP,O->Epoch-O->tp,
O->PosN,O->VelN,&O->anom);
}
/* Skip RV and FILE */
for(j=0;j<4;j++) fscanf(infile,"%[^\n] %[\n]",junk,&newline);
}
else if (InputType == INP_POSVEL) {
/* Skip KEPLER section */
for(j=0;j<7;j++) fscanf(infile,"%[^\n] %[\n]",junk,&newline);
fscanf(infile,"%lf %lf %lf %[^\n] %[\n]",
&O->PosN[0],&O->PosN[1],&O->PosN[2],
junk,&newline);
fscanf(infile,"%lf %lf %lf %[^\n] %[\n]",
&O->VelN[0],&O->VelN[1],&O->VelN[2],
junk,&newline);
for(j=0;j<3;j++){
O->PosN[j] *= 1.0E3;
O->VelN[j] *= 1.0E3;
}
RV2Eph(O->Epoch,O->mu,O->PosN,O->VelN,
&O->SMA,&O->ecc,&O->inc,&O->RAAN,
&O->ArgP,&O->anom,&O->tp,
&O->SLR,&O->alpha,&O->rmin,
&O->MeanMotion,&O->Period);
/* Skip FILE section */
for(j=0;j<2;j++) fscanf(infile,"%[^\n] %[\n]",junk,&newline);
}
else if (InputType == INP_FILE) {
for(j=0;j<9;j++) fscanf(infile,"%[^\n] %[\n]",junk,&newline);
fscanf(infile,"%s \"%[^\"]\" %[^\n] %[\n]",
response,ElementLabel,junk,&newline);
ElementType = DecodeString(response);
fscanf(infile,"\"%[^\"]\" %[^\n] %[\n]",ElementFileName,junk,&newline);
if (ElementType == INP_TLE) {
Success = LoadTleFromFile(InOutPath,ElementFileName,
ElementLabel,JulDay,O->mu,O);
if (!Success) {
printf("Error loading TLE %s from file %s.\n",
ElementLabel,ElementFileName);
exit(1);
}
}
else if (ElementType == INP_TRV) {
Success = LoadTRVfromFile(InOutPath, ElementFileName,
ElementLabel, AbsTime, O);
if (!Success) {
printf("Error loading TRV %s from file %s.\n",
ElementLabel,ElementFileName);
exit(1);
}
}
else {
printf("Oops. Unknown ElementType in InitOrbit.\n");
exit(1);
}
}
else {
printf("Oops. Unknown InputType in InitOrbit.\n");
exit(1);
}
FindCLN(O->PosN,O->VelN,O->CLN,O->wln);
/* Skip THREE_BODY section */
for(j=0;j<17;j++) fscanf(infile,"%[^\n] %[\n]",junk,&newline);
}
else if (O->Regime == ORB_THREE_BODY) {
/* Skip ZERO, FLIGHT, and CENTRAL sections */
for(j=0;j<21;j++) fscanf(infile,"%[^\n] %[\n]",junk,&newline);
fscanf(infile,"%[^\n] %[\n]",junk,&newline);
fscanf(infile,"%s %[^\n] %[\n]",response,junk,&newline);
O->Sys = DecodeString(response);
if (!LagSys[O->Sys].Exists) {
printf("Oops. Orbit %ld depends on a Lagrange System that doesn't exist.\n",O->Tag);
exit(1);
}
O->Body1 = LagSys[O->Sys].Body1;
O->Body2 = LagSys[O->Sys].Body2;
O->mu1 = LagSys[O->Sys].mu1;
O->mu2 = LagSys[O->Sys].mu2;
fscanf(infile,"%s %[^\n] %[\n]",response,junk,&newline);
O->LagDOF = DecodeString(response);
fscanf(infile,"%s %[^\n] %[\n]",response,junk,&newline);
InputType = DecodeString(response);
if (InputType == INP_MODES) { /* Initial modes given */
fscanf(infile,"%s %[^\n] %[\n]",response,junk,&newline);
O->LP = DecodeString(response);
fscanf(infile,"%lf %[^\n] %[\n]",
&AmpXY1,junk,&newline);
fscanf(infile,"%lf %[^\n] %[\n]",
&PhiXY1,junk,&newline);
fscanf(infile,"%s %[^\n] %[\n]",response,junk,&newline);
if (DecodeString(response) == DIR_CCW) SenseXY1 = 1.0;
else SenseXY1 = -1.0;
fscanf(infile,"%lf %[^\n] %[\n]",
&AmpXY2,junk,&newline);
fscanf(infile,"%lf %[^\n] %[\n]",
&PhiXY2,junk,&newline);
fscanf(infile,"%s %[^\n] %[\n]",response,junk,&newline);
if (DecodeString(response) == DIR_CCW) SenseXY2 = 1.0;
else SenseXY2 = -1.0;
fscanf(infile,"%lf %[^\n] %[\n]",
&AmpZ,junk,&newline);
fscanf(infile,"%lf %[^\n] %[\n]",
&PhiZ,junk,&newline);
AmpXY1 *= 1000.0;
AmpXY2 *= 1000.0;
AmpZ *= 1000.0;
PhiXY1 *= D2R;
PhiXY2 *= D2R;
PhiZ *= D2R;
AmpPhase2LagModes(0.0,AmpXY1,PhiXY1,SenseXY1,
AmpXY2,PhiXY2,SenseXY2,AmpZ,PhiZ,
&LagSys[O->Sys],O);
/* Find r,v from modal description */
LagModes2RV(AbsTime,&LagSys[O->Sys],O,O->PosN,O->VelN);
/* Skip XYZ and FILE sections */
for(j=0;j<4;j++) fscanf(infile,"%[^\n] %[\n]",junk,&newline);
}
else if (InputType == INP_XYZ) {
/* Skip MODES section */
for(j=0;j<9;j++) fscanf(infile,"%[^\n] %[\n]",junk,&newline);
fscanf(infile,"%lf %lf %lf %[^\n] %[\n]",
&O->x,&O->y,&O->z,junk,&newline);
fscanf(infile,"%lf %lf %lf %[^\n] %[\n]",
&O->xdot,&O->ydot,&O->zdot,junk,&newline);
XYZ2LagModes(0.0,&LagSys[O->Sys],O);
LagModes2RV(AbsTime,&LagSys[O->Sys],O,O->PosN,O->VelN);
/* Skip FILE section */
for(j=0;j<2;j++) fscanf(infile,"%[^\n] %[\n]",junk,&newline);
}
else if (InputType == INP_FILE) {
fscanf(infile,"%s %[^\n] %[\n]",response,junk,&newline);
O->LP = DecodeString(response);
/* Skip MODES and XYZ sections */
for(j=0;j<10;j++) fscanf(infile,"%[^\n] %[\n]",junk,&newline);
fscanf(infile,"%s \"%[^\"]\" %[^\n] %[\n]",
response,ElementLabel,junk,&newline);
ElementType = DecodeString(response);
fscanf(infile,"\"%[^\"]\" %[^\n] %[\n]",ElementFileName,junk,&newline);
if (ElementType == INP_TRV) {
Success = LoadTRVfromFile(InOutPath, ElementFileName,
ElementLabel, AbsTime, O);
if (!Success) {
printf("Error loading TRV %s from file %s.\n",
ElementLabel,ElementFileName);
exit(1);
}
}
else if (ElementType == INP_SPLINE) {
O->SplineFile = FileOpen(InOutPath,ElementFileName,"rt");
for(i=0;i<4;i++) {
fscanf(O->SplineFile," %ld:%ld:%ld:%ld:%ld:%lf %lf %lf %lf %lf %lf %lf %[\n]",
&NodeYear,&NodeMonth,&NodeDay,&NodeHour,&NodeMin,&NodeSec,
&O->NodePos[i][0],&O->NodePos[i][1],&O->NodePos[i][2],
&O->NodeVel[i][0],&O->NodeVel[i][1],&O->NodeVel[i][2],
&newline);
O->NodeAbsTime[i] = DateToAbsTime(NodeYear,NodeMonth,NodeDay,
NodeHour,NodeMin,NodeSec);
for(j=0;j<3;j++) {
O->NodePos[i][j] *= 1000.0;
O->NodeVel[i][j] *= 1000.0;
}
if (AbsTime < O->NodeAbsTime[1]) {
printf("Oops. Spline file beginning is in the future.\n");
exit(1);
}
}
SplineToPosVel(O);
}
else {
printf("Oops. Unknown ElementType in InitOrbit.\n");
exit(1);
}
}
else {
printf("Oops. Unknown Input Type in InitOrbit.\n");
exit(1);
}
O->World = O->Body1;
O->mu = O->mu1;
O->SMA = MAGV(O->PosN); /* For sake of EH */
FindCLN(O->PosN,O->VelN,O->CLN,O->wln);
O->MeanMotion = LagSys[O->Sys].MeanRate;
O->Period = TwoPi/O->MeanMotion;
}
else {
printf("Bogus Orbit Regime in file %s\n",O->FileName);
exit(1);
}
/* .. Formation Frame Parameters */
F = &Frm[O->Tag];
fscanf(infile,"%[^\n] %[\n]",junk,&newline);
fscanf(infile,"%s %[^\n] %[\n]",response,junk,&newline);
F->FixedInFrame = response[0];
fscanf(infile,"%lf %lf %lf %ld %[^\n] %[\n]",
&Ang1,&Ang2,&Ang3,&Seq,junk,&newline);
A2C(Seq,Ang1*D2R,Ang2*D2R,Ang3*D2R,F->CN);
if(F->FixedInFrame == 'L') {
/* Adjust CFN */
for(j=0;j<3;j++){
for(k=0;k<3;k++) F->CL[j][k] = F->CN[j][k];
}
MxM(F->CL,O->CLN,F->CN);
}
fscanf(infile,"%s %[^\n] %[\n]",response,junk,&newline);
FrmExpressedIn = response[0];
fscanf(infile,"%lf %lf %lf %[^\n] %[\n]",
&F->PosR[0],&F->PosR[1],&F->PosR[2],junk,&newline);
if (FrmExpressedIn == 'L') {
for(j=0;j<3;j++) p[j] = F->PosR[j];
MTxV(O->CLN,p,F->PosR);
}
fclose(infile);
}
/**********************************************************************/
void InitRigidDyn(struct SCType *S)
{
long i,j,Ig,Ia,Jg,Jb,Ibody,Ib,u0,x0,c0,Nu,Nx;
struct JointType *G;
struct DynType *D;
FILE *outfile;
char filename[80];
D = &S->Dyn;
/* .. Tree Tables */
/* Connectivity Table */
/* Inner body -> -1, Outer body -> +1, else 0 */
D->ConnectTable = (long **) calloc(S->Nb,sizeof(long *));
for(i=0;i<S->Nb;i++)
D->ConnectTable[i] = (long *) calloc(S->Ng,sizeof(long));
for(Ib=0;Ib<S->Nb;Ib++) {
for(Ig=0;Ig<S->Ng;Ig++) {
D->ConnectTable[Ib][Ig] = 0;
}
}
for(Ig=0;Ig<S->Ng;Ig++) {
D->ConnectTable[S->G[Ig].Bin][Ig] = -1;
D->ConnectTable[S->G[Ig].Bout][Ig] = 1;
}
/* Joint Path Table */
/* Joint in path -> 1, else 0 */
D->JointPathTable = (struct JointPathTableType **)
calloc(S->Nb,sizeof(struct JointPathTableType *));
for(i=0;i<S->Nb;i++)
D->JointPathTable[i] = (struct JointPathTableType *)
calloc(S->Ng,sizeof(struct JointPathTableType));
for(Ibody=0;Ibody<S->Nb;Ibody++) {
Ib = Ibody;
while(Ib > 0) {
Ig = S->B[Ib].Gin;
D->JointPathTable[Ibody][Ig].InPath = 1;
Ib = S->G[Ig].Bin;
}
}
/* Body Path Table */
/* Body in path -> 1, else 0 */
D->BodyPathTable = (struct BodyPathTableType **)
calloc(S->Nb,sizeof(struct BodyPathTableType *));
for(i=0;i<S->Nb;i++)
D->BodyPathTable[i] = (struct BodyPathTableType *)
calloc(S->Nb,sizeof(struct BodyPathTableType));
for(Ibody=0;Ibody<S->Nb;Ibody++) {
Ib = Ibody;
while(Ib > 0) {
Ig = 0;
while(S->G[Ig].Bout != Ib) Ig++;
D->BodyPathTable[Ibody][Ib].InPath = 1;
Ib = S->G[Ig].Bin;
}
D->BodyPathTable[Ibody][0].InPath = 1;
}
/* Find ancestor joint list for each joint */
for(Ig=0;Ig<S->Ng;Ig++) {
G = &S->G[Ig];
Ib = S->G[Ig].Bin;
G->Nanc = 0;
while(Ib > 0) {
G->Nanc++;
Jg = S->B[Ib].Gin;
Ib = S->G[Jg].Bin;
}
G->Anc = (long *) calloc(G->Nanc,sizeof(long));
Ib = S->G[Ig].Bin;
Ia = 0;
while(Ib > 0) {
Jg = S->B[Ib].Gin;
G->Anc[Ia] = Jg;
Ib = S->G[Jg].Bin;
Ia++;
}
}
/* Determine sizes of state vectors */
D->Nu = 6;
D->Nx = 7;
u0 = 3;
x0 = 4;
D->Nc = 0;
c0 = 0;
for(Ig=0;Ig<S->Ng;Ig++) {
G = &S->G[Ig];
if (G->IsSpherical) {
G->RotDOF = 3;
G->RotSeq = 123;
D->Nu += 3;
D->Nx += 4;
G->Rotu0 = u0;
G->Rotx0 = x0;
u0 += 3;
x0 += 4;
}
else { /* Is Gimbal */
D->Nu += G->RotDOF;
D->Nx += G->RotDOF;
G->Rotu0 = u0;
G->Rotx0 = x0;
u0 += G->RotDOF;
x0 += G->RotDOF;
G->Rotc0 = c0;
c0 += 3-G->RotDOF;
}
D->Nu += G->TrnDOF;
D->Nx += G->TrnDOF;
G->Trnu0 = u0;
G->Trnx0 = x0;
u0 += G->TrnDOF;
x0 += G->TrnDOF;
G->Trnc0 = c0;
c0 += 3-G->TrnDOF;
}
/* .. Allocate Workspace */
D->PAngVel = CreateMatrix(3*S->Nb,D->Nu);
D->IPAngVel = CreateMatrix(3*S->Nb,D->Nu);
D->PVel = CreateMatrix(3*S->Nb,D->Nu);
D->mPVel = CreateMatrix(3*S->Nb,D->Nu);
D->BodyTrq = (double *) calloc(3*S->Nb,sizeof(double));
D->BodyFrc = (double *) calloc(3*S->Nb,sizeof(double));
D->u = (double *) calloc(D->Nu,sizeof(double));
D->uu = (double *) calloc(D->Nu,sizeof(double));
D->du = (double *) calloc(D->Nu,sizeof(double));
D->udot = (double *) calloc(D->Nu,sizeof(double));
D->x = (double *) calloc(D->Nx,sizeof(double));
D->xx = (double *) calloc(D->Nx,sizeof(double));
D->dx = (double *) calloc(D->Nx,sizeof(double));
D->xdot = (double *) calloc(D->Nx,sizeof(double));
D->h = (double *) calloc(S->Nw,sizeof(double));
D->hh = (double *) calloc(S->Nw,sizeof(double));
D->dh = (double *) calloc(S->Nw,sizeof(double));
D->hdot = (double *) calloc(S->Nw,sizeof(double));
for(i=0;i<3;i++) {
D->PAngVel[i][i] = 1.0;
for(j=0;j<3;j++) D->IPAngVel[i][j] = S->B[0].I[i][j];
}
for(Ib=0;Ib<S->Nb;Ib++) {
for(i=0;i<3;i++) {
D->PVel[3*Ib+i][D->Nu-3+i] = 1.0;
D->mPVel[3*Ib+i][D->Nu-3+i] = S->B[Ib].mass;
}
}
if (S->ConstraintsRequested) {
D->Nc = 6*S->Nb - D->Nu;
D->PAngVelc = CreateMatrix(3*S->Nb,D->Nc);
D->PVelc = CreateMatrix(3*S->Nb,D->Nc);
D->TotalTrq = (double *) calloc(3*S->Nb,sizeof(double));
D->TotalFrc = (double *) calloc(3*S->Nb,sizeof(double));
D->GenConstraintFrc = (double *) calloc(D->Nc,sizeof(double));
}
MapJointStatesToStateVector(S);
/* .. Echo tree tables */
sprintf(filename,"Tree%02ld.42",S->ID);
outfile = FileOpen(InOutPath,filename,"w");
fprintf(outfile,"SC %2ld: Nb = %2ld Ng = %2ld\n\n",S->ID,S->Nb,S->Ng);
fprintf(outfile,"Connect Table:\n\n");
fprintf(outfile," ");
for(Ig=0;Ig<S->Ng;Ig++) fprintf(outfile," G[%02ld]",Ig);
fprintf(outfile,"\n");
for(Ib=0;Ib<S->Nb;Ib++) {
fprintf(outfile,"B[%02ld]:",Ib);
for(Ig=0;Ig<S->Ng;Ig++) {
fprintf(outfile," %3ld ",D->ConnectTable[Ib][Ig]);
}
fprintf(outfile,"\n");
}
fprintf(outfile,"\n\n\nJoint Path Table:\n\n");