Newer
Older
/* This program solves the relativistic sphere with an
iterative method (conjugate gradients). Dynamic case.
It is the c translation of the original fortran program
solvergaia.for
M.G. Lattanzi, A. Vecchiato, B. Bucciarelli (23 May 1996)
A. Vecchiato, R. Morbidelli for the Fortran 90 version with
dynamical memory allocation (21 March 2005)
A. Vecchiato, June 16, 2008
Version 2.1 , Feb 8, 2012
Version history:
- version 2.1, Feb 8 2012 - Added debug mode
- version 2.0, Jan 27 2012 - Added Checkpoint & Restart
- version 1.2, Jan 24 2012 -
- version 5.0 - May 2013 from Ugo Becciani and Alberto Vecchiato
*/
//#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <dirent.h>
#include <math.h>
#include "lsqr.h"
#include <time.h>
#include <mpi.h>
#include "util.h"
#ifdef OMP
#include <omp.h>
#endif
#define MAX_CONSTR 1000
long instr_hash(int FoV, int CCD, int PixelColumn, int TimeInterval);
long randlong(long max);
long randlong1(long min, long max);
int randint(int max);
int randint1(int min, int max);
int fill_extract(long *values, long *pos_min, long pos_max, long *number);
int main(int argc, char **argv) {
int debugMode,wrsol;
int idtest=0, precond=1;
int inputDirOpt=0, outputDirOpt=0, inputDirLen;
char inputDir[1024]="", outputDir[1024]="",wrfileDir[1024]="";
char filenameSolProps[150];
char filenameSolPropsFinal[150];
char filenameAstroResults[150]; /* file storing the Astrometric Parameters */
char filenameAttResults[150]; /* file storing the Attitude Parameters */
char filenameInstrResults[150]; /* file storing the Instrument Parameters */
char filenameGlobalResults[150]; /* file storing the Global Parameters */
long ii, jj, kk;
long sphereId; // Id of the sphere to be solved
long idum; // variable to initialize the random number generator aggiunta la variabile per inizializzare ran2()
long itnlim; // maximum number of iteration allowed for the LSQR convergence
double damp, atol, btol, conlim; // other LSQR input parameters
double aTol; //read by command line, overrides atol if >=0
int istop; // LSQR stopping condition
int itn; // LSQR iteration number
double anorm, acond, rnorm, arnorm, xnorm; // other LSQR output parameters
// Properties of the system to be solved
// Astrometric parameters:
long nStar; // number of stars
short nAstroP; // number of astrometric parameters for each observation
short nAstroPSolved,nInstrPSolved; // number of astrometric and instrumental parameters taken as unknowns in the system of equations
int *mapAstroP; // indeces of the solved astrometric parameters
int lsInstrFlag,ssInstrFlag,nuInstrFlag,maInstrFlag;
int nElemIC=0,nOfInstrConstr=0;
int nOfInstrConstrLSAL=0, nElemICLSAL=0, nOfInstrConstrLSAC=0, nElemICLSAC=0 , nOfInstrConstrSS=0 ,nElemICSS=0;
long nDegFreedomAtt=0; // number of degrees of freedom for each attitude axis
long cCDLSAACZP=14; // CCD light sensitive area AC zero point
short nAttAxes=0, nAttParAxis; // number of attitude axes to be reconstructed, number of non-zero attitude coefficients per obs. & axis
short nAttP=0; // number of attitude parameters for each observation
// Instrument parameters:
long instrSetUp; // number coding the set up of the instrument in terms of: # of FoVs, # of CCDs, # of pixel columns, # of time intervals
short nInstrP; // number of instrument parameters for each observation
// Global parameters:
short nGlobP; // number of global parameters
long nobs; // number of observations
long nConstrLong, nConstrLat, nConstrMuLong, nConstrMuLat; // number of constraints for the astrometric parameters
long *constrLongId, *constrLatId, *constrMuLongId, *constrMuLatId; // arrays with the gsrIDs of the constrained sources
double *constrLongW, *constrLatW, *constrMuLongW, *constrMuLatW; // arrays with the weights of the constraints
double extConstrW; // weight of the null space constraint equations
double barConstrW; // weight of the baricentric constraint equations
const double attExtConstrFact=-0.5; // the coefficients of the attitude part of the null space constraint equations must be multiplied by a factor -1/2
int nAttParam, nInstrParam, nGlobalParam,nInstrParamTot; // total number of unknowns for the Astrometric, Attitude, Instrument, and Global parameters respectively
int nparam; // total number of unknowns
long ncoeff, ielem, global_ielem, precnofrows,global_precnofrows, ncolumn, nrowsToRead;
long offsetAttParam, offsetInstrParam, offsetGlobParam, VroffsetAttParam; // offests for the Attitude, Instrument, and Global columns of the coefficient matrix
unsigned long int totmem, nElements; // total required memory and temporary variable to store the memory being allocated
long VrIdAstroPDimMax=0; //
long VrIdAstroPDim=0; //
long VrIdAstroPDimRecv;
int offset;
long nObsxStar, nobsOri;
int nfileProc=3;
int addElementAtt=0;
int addElementextStar=0;
int addElementbarStar=0;
int nOfElextObs=0;
int nOfElBarObs=0;
// Array arguments of the LSQR function
double *knownTerms, *vVect, *wVect, *xSolution, *standardError; // arrays containing the known terms (knownterms), the bidiagonalization (wVect, wVect), the unknowns (xSolution), and the estimated variances (standardError)
long int *matrixIndex; // ia[i] contains the column number of the coefficient systemMatrix[i]
int *instrCol; // columns on each observation for instumental Parameters
int * instrConstrIlung; // vector containing the length of each instrConstr eq.
double *systemMatrix, *preCondVect; // array of the non-zero coefficients of the system and of the column normalization respectively
/////////////////////
// Arrays containing the solution coming from the LSQR
double *xAstro, *standardErrorAstro; // solution and standard errors for the Astrometric parameters
double *xAtt, *standardErrorAtt; // solution and standard errors for the Attitude parameters
double *xInstr, *standardErrorInstr; // solution and standard errors for the Instrument parameters
double *xGlobal, *standardErrorGlobal; // solution and standard errors for the Global parameters
FILE *fpSolProps,*fpSolPropsFinal,*fpSolPropsFileBin;
FILE *fpMI, *fpSM, *fpII, *fpKT, *fpCPR;
FILE *fpAstroR, *fpAttR, *fpInstrR, *fpGlobR, *ffcont;
time_t seconds[10], tot_sec[10];
seconds[0] = time(NULL);
double timeToReadFiles;
int nproc, myid, namelen;
double startTime,endTime;
long int * mapNcoeff, * mapNoss;
long int mapNcoeffBefore, mapNossBefore;
long int mapNcoeffAfter, mapNossAfter;
int timeCPR, timeLimit,itnCPR,itnCPRstop=1000000;
int itnLimit; //read by command line, overrides itnlim if >0
struct comData comlsqr;
// serach for map
long lastStar=-1;
long firstStar=-1;
long lastStarConstr=-1;
long firstStarConstr=-1;
int seqStar=1;
int withFile=1;
int noConstr=0;
int zeroAtt=0, zeroInstr=0, zeroGlob=0, wrFilebin=0;
int constraintFound[MAX_CONSTR][2]; // first: number of file of the constraint; second: row in file
int rowInFile=0;
int noIter=0;
int noCPR=0;
int extConstraint=0, nEqExtConstr=0;
int barConstraint=0, nEqBarConstr=0;
int startingAttColExtConstr,endingAttColExtConstr,numOfExtAttCol,starOverlap=0,numOfExtStar,numOfBarStar;
struct dirent **namelistMI;
struct nullSpace nullSpaceCk;
double nullSpaceAttfact;
int autoRun=0;
float memGlobal=0;
for (int i=1;i<argc-1;i++)
Loading full blame...