Newer
Older
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
#include <stdlib.h>
#include <stdio.h>
#include "util.h"
#include <mpi.h>
#include <math.h>
#ifdef OMP
#include <omp.h>
#endif
#define __MSGSIZ_MAX 100000
/* The function instrIndexIdToColIndexGlobal gets *instrIndexPointer and *instrConst, and computes *matrixIndexIntsr,
which contains the columns of the 6 instrument parameters in the design matrix.
The input pointers refers to:
a) which FoV, CCD, PixelColumn, and TimeInterval each observation has occurred according to the following schema
instrIndexPointer[0]=FoV instrIndexPointer[1]=CCD instrIndexPointer[2]=PixelColumn instrIndexPointer[3]=TimeInterval
b) the characteristics of the instrument according to the following schema
instrConst[0]=nFoVs instrConst[1]=nCCDs instrConst[2]=nPixelColumns instrConst[3]=nTimeIntervals
For performance reasons, it accepts some (five) pre-calculated constant offsets, i.e.:
1) offsetCMag = nCCDs = instrConst[1]
2) offsetCnu = nCCDs*(1+nFoVs) = instrConst[1]*(1+instrConst[0])
3) offsetCdelta_eta = nCCDs*(1+nFoVs+nPixelColumns) = instrConst[1]*(1+instrConst[0]+instrConst[2])
4) offsetCDelta_eta_1 = nCCDs*(1+nFoVs*(1+nTimeIntervals)+nPixelColumns) = instrConst[1]*(1+instrConst[0]*(1+instrConst[3])+instrConst[2])
5) offsetCDelta_eta_2 = nCCDs*(1+nFoVs*(1+2*nTimeIntervals)+nPixelColumns) = instrConst[1]*(1+instrConst[0]*(1+2*instrConst[3])+instrConst[2])
*/
void instrIndexIdToColIndexGlobal(int* instrIndexPointer, int* instrConst,int totrows ,struct comData comlsqr, int* instrCols)
{
long relPos_ls;
int nInstrParam=comlsqr.nInstrParam;
short nInstrPSolved=comlsqr.nInstrPSolved;
int maInstrFlag=comlsqr.maInstrFlag;
int nuInstrFlag=comlsqr.nuInstrFlag;
int ssInstrFlag=comlsqr.ssInstrFlag;
int lsInstrFlag=comlsqr.lsInstrFlag;
int nFoVs =1+instrConst[0];
int nCCDs = instrConst[1];
int nPixCols = instrConst[2];
int nTInts = instrConst[3];
for(int jj=0;jj<totrows;jj++){
if(instrIndexPointer[jj*(DEFAULT_NINSTRINDEXES+1)]==-1){ //is a Constraint
for(int kk=0;kk<nInstrPSolved;kk++)
instrCols[jj*nInstrPSolved+kk]=0;
continue;
}
// FoV = instrIndexPointer[jj*DEFAULT_NINSTRINDEXES], CCD = instrIndexPointer[jj*DEFAULT_NINSTRINDEXES+1]
// PixelColumn = instrIndexPointer[jj*DEFAULT_NINSTRINDEXES+2], TimeInterval = instrIndexPointer[jj*DEFAULT_NINSTRINDEXES+3]
int FoV = instrIndexPointer[jj*(DEFAULT_NINSTRINDEXES+1)];
int CCD = instrIndexPointer[jj*(DEFAULT_NINSTRINDEXES+1)+1];
int PixCol = instrIndexPointer[jj*(DEFAULT_NINSTRINDEXES+1)+2];
int TInt = instrIndexPointer[jj*(DEFAULT_NINSTRINDEXES+1)+3];
int ACALFlag = instrIndexPointer[jj*(DEFAULT_NINSTRINDEXES+1)+4];
int counter=0;
if(maInstrFlag) {
instrCols[jj*nInstrPSolved+counter] = CCD-1; // Index_CMag = CCD-1
counter++;
}
if(nuInstrFlag) {
// Index_Cnu = offsetCMag + (FoV−1)*nCCDs + (CCD−1)
instrCols[jj*nInstrPSolved+counter] = comlsqr.offsetCMag + FoV*nCCDs + (CCD-1);
counter++;
}
if(ssInstrFlag) {
if(ACALFlag) {
// Index Cdelta_zeta = offsetCDelta_eta_3 + (CCD−1)*nPixelColumns + (PixelColumn−1)
instrCols[jj*nInstrPSolved+counter] = comlsqr.offsetCDelta_eta_3 + (CCD-1)*nPixCols + (PixCol-1);
counter++;
} else {
// Index Cdelta_eta = offsetCnu + (CCD−1)*nPixelColumns + (PixelColumn−1)
instrCols[jj*nInstrPSolved+counter] = comlsqr.offsetCnu + (CCD-1)*nPixCols + (PixCol-1);
counter++;
}
}
// For performance reasons, compute the relative Delta_eta index only once
// relPos_Delta_eta = (FoV-1)*nCCDs*nTimeIntervals+(CCD-1)*nTimeIntervals+(TimeInterval-1)
// = (instrIndexPointer[0]-1)*instrConst[1]*instrConst[3]+(instrIndexPointer[1]-1)*instrConst[3]+(instrIndexPointer[3]-1)
if(lsInstrFlag) {
relPos_ls = FoV*nCCDs*nTInts+(CCD-1)*nTInts+(TInt-1);
if(ACALFlag) {
// Index CDelta_zeta_1 = offsetCdelta_zeta + relPos_Delta_zeta
instrCols[jj*nInstrPSolved+counter] = comlsqr.offsetCdelta_zeta + relPos_ls;
counter++;
// Index CDelta_zeta_2 = offsetCDelta_zeta_1 + relPos_Delta_zeta
instrCols[jj*nInstrPSolved+counter] = comlsqr.offsetCDelta_zeta_1 + relPos_ls;
counter++;
// Index CDelta_zeta_3 = offsetCDelta_zeta_2 + relPos_Delta_zeta
instrCols[jj*nInstrPSolved+counter] = comlsqr.offsetCDelta_zeta_2 + relPos_ls;
counter++;
} else {
// Index CDelta_eta_1 = offsetCdelta_eta + relPos_Delta_zeta
instrCols[jj*nInstrPSolved+counter] = comlsqr.offsetCdelta_eta + relPos_ls;
counter++;
// Index CDelta_eta_2 = offsetCDelta_eta_1 + relPos_Delta_zeta
instrCols[jj*nInstrPSolved+counter] = comlsqr.offsetCDelta_eta_1 + relPos_ls;
counter++;
// Index CDelta_eta_3 = offsetCDelta_eta_2 + relPos_Delta_zeta
instrCols[jj*nInstrPSolved+counter] = comlsqr.offsetCDelta_eta_2 + relPos_ls;
counter++;
}
}
// }
if(counter!=nInstrPSolved) {
printf("SEVERE ERROR PE=%d counter=%d != nInstrPSolved=%d on row #%d\n",comlsqr.myid, counter, nInstrPSolved, jj);
MPI_Abort(MPI_COMM_WORLD, 1);
exit(EXIT_FAILURE);
}
for(int k=0;k<nInstrPSolved;k++){
if(instrCols[jj*nInstrPSolved+k]>=nInstrParam ||instrCols[jj*nInstrPSolved+k]<0 ){
printf("SEVERE ERROR on instrCols[%d]=%d > nInstrparam=%d\n",jj*nInstrPSolved+k,instrCols[jj*nInstrPSolved+k],nInstrParam);
MPI_Abort(MPI_COMM_WORLD, 1);
exit(EXIT_FAILURE);
}
}
}
return;
}
void ColIndexToinstrIndexIdGlobal(int* instrIndexPointer, int* instrConst,int totrows ,struct comData comlsqr, int* instrCols)
{
long relPos_Delta_eta;
int testConstr=0;
for(int jj=0;jj<totrows;jj++){
testConstr=0;
for(int k=0;k<6;k++){
testConstr+=instrCols[jj*DEFAULT_NINSTRVALUES+k];
}
if(testConstr==0){ //is a Constraint
instrIndexPointer[jj*DEFAULT_NINSTRINDEXES+0]=0;
instrIndexPointer[jj*DEFAULT_NINSTRINDEXES+1]=0;
instrIndexPointer[jj*DEFAULT_NINSTRINDEXES+2]=0;
instrIndexPointer[jj*DEFAULT_NINSTRINDEXES+3]=0;
continue;
}
// Index_CMag = CCD-1
instrIndexPointer[jj*DEFAULT_NINSTRINDEXES+1]=instrCols[jj*DEFAULT_NINSTRVALUES+0]+1;
// Index_Cnu = offsetCMag + (FoV−1)*nCCDs + (CCD−1)
instrIndexPointer[jj*DEFAULT_NINSTRINDEXES+0]=(instrCols[jj*DEFAULT_NINSTRVALUES+1]-instrIndexPointer[jj*DEFAULT_NINSTRINDEXES+1]+1-comlsqr.offsetCMag)/instrConst[1] + 1;
// Index Cdelta_eta = offsetCnu + (CCD−1)*nPixelColumns + (PixelColumn−1)
instrIndexPointer[jj*DEFAULT_NINSTRINDEXES+2]=instrCols[jj*DEFAULT_NINSTRVALUES+2]-comlsqr.offsetCnu-(instrIndexPointer[jj*DEFAULT_NINSTRINDEXES+1]-1)*instrConst[2]+1;
relPos_Delta_eta=instrCols[jj*DEFAULT_NINSTRVALUES+3]-comlsqr.offsetCdelta_eta;
instrIndexPointer[jj*DEFAULT_NINSTRINDEXES+3]=relPos_Delta_eta -(instrIndexPointer[jj*DEFAULT_NINSTRINDEXES+0]-1)*instrConst[1]*instrConst[3]-(instrIndexPointer[jj*DEFAULT_NINSTRINDEXES+1]-1)*instrConst[3]+1;
}
return;
}
/*--------------------------------------------------------------------------*/
void printerror(int status) {
/*****************************************************/
/* Print out cfitsio error messages and exit program */
/*****************************************************/
if (status) {
// fits_report_error(stderr, status); /* print error report */
MPI_Abort(MPI_COMM_WORLD, status);
exit(status); /* terminate the program, returning error status */
}
return;
}
/*--------------------------------------------------------------------------*/
void printerrorsingle(int status) {
/*****************************************************/
/* Print out cfitsio error messages and exit program */
/*****************************************************/
if (status) {
// fits_report_error(stderr, status); /* print error report */
exit(status); /* terminate the program, returning error status */
}
return;
}
int err_malloc(const char *s,int id) {
printf("out of memory while allocating %s on PE=%d.\n", s, id);
MPI_Abort(MPI_COMM_WORLD, 1);
return 1;
}
int sel(const struct dirent *a) {
return ((strncmp(a->d_name, "dpccu3dpctavugsrgsrsystemrow", 28) == 0) ? 1 : 0);
}
int selextConstrStar(const struct dirent *a) {
return ((strstr(a->d_name, "nullspaceastrofit") != NULL) ? 1 : 0);
}
int selextConstrAtt(const struct dirent *a) {
return ((strstr(a->d_name, "nullspaceattitudefit") != NULL) ? 1 : 0);
}
int selbarConstrStar(const struct dirent *a) {
return ((strstr(a->d_name, "barconstrastrofit") != NULL) ? 1 : 0);
}
int selSM(const struct dirent *a) {
return ((strstr(a->d_name, "_SM.bin") != NULL) ? 1 : 0);
}
Loading full blame...