MCPcopy Create free account
hub / github.com/CruiserOne/Astrolog / SwissComputeStarSort

Function SwissComputeStarSort

calc.cpp:3099–3183  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3097// the order stars are returned.
3098
3099flag SwissComputeStarSort(real jd, ES *pes)
3100{
3101 static int ces = 0, istar = 0;
3102 int i, j;
3103 ES es, *pes2;
3104
3105 // Simple cases when not sorting or when sorted list has been created.
3106 if (us.nStarSort <= 0)
3107 return SwissComputeStar(jd, pes);
3108 if (pes != NULL) {
3109 if (istar >= ces)
3110 return fFalse;
3111 *pes = is.rgesSort[istar];
3112 istar++;
3113 return fTrue;
3114 }
3115
3116 // Allocate list and put all stars within it.
3117 ces = 1500;
3118 if (ces > is.cesSort) {
3119 if (is.rgesSort != NULL)
3120 DeallocateP(is.rgesSort);
3121 is.rgesSort = RgAllocate(ces, ES, "star sort");
3122 if (is.rgesSort == NULL)
3123 return fFalse;
3124 is.cesSort = ces;
3125 }
3126 SwissComputeStar(jd, pes);
3127 for (i = 0; i < 1500 && SwissComputeStar(jd, &is.rgesSort[i]); i++)
3128 ;
3129 ces = i;
3130 istar = 0;
3131
3132 // Temporarily convert pointers to offsets, since sorting may move them.
3133 for (i = 0; i < ces; i++) {
3134 pes2 = &is.rgesSort[i];
3135 pes2->pchNam = (char *)(pes2->pchNam - pes2->sz);
3136 if (*pes2->pchDes)
3137 pes2->pchDes = (char *)(pes2->pchDes - pes2->sz);
3138 pes2->pchBest = (char *)(pes2->pchBest - pes2->sz);
3139 }
3140 for (i = 1; i < ces; i++) {
3141 j = i-1;
3142
3143 // Compare star names for -Un switch.
3144 if (us.nStarSort == 'n') while (j >= 0 && NCompareSz(
3145 is.rgesSort[j].sz + (time_t)is.rgesSort[j].pchBest,
3146 is.rgesSort[j+1].sz + (time_t)is.rgesSort[j+1].pchBest) > 0) {
3147 SwapTemp(is.rgesSort[j], is.rgesSort[j+1], es);
3148 j--;
3149
3150 // Compare star brightnesses for -Ub switch.
3151 } else if (us.nStarSort == 'b') while (j >= 0 &&
3152 is.rgesSort[j].mag > is.rgesSort[j+1].mag) {
3153 SwapTemp(is.rgesSort[j], is.rgesSort[j+1], es);
3154 j--;
3155
3156 // Compare star zodiac locations for -Uz switch.

Callers 4

PrintObjectsFunction · 0.85
ChartListingFunction · 0.85
ChartHorizonFunction · 0.85
ChartOrbitFunction · 0.85

Calls 3

SwissComputeStarFunction · 0.85
DeallocatePFunction · 0.85
NCompareSzFunction · 0.85

Tested by

no test coverage detected