From 088f2d0fd0ba0da157df1ad810aa166c6f9e7ac6 Mon Sep 17 00:00:00 2001 From: Sarod Yatawatta Date: Tue, 27 Feb 2018 14:38:57 +0100 Subject: [PATCH 1/7] fix (double) allocation instead of (int) --- src/lib/Dirac/lbfgs_nocuda.c | 2 +- src/lib/Dirac/robust_lbfgs_nocuda.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/Dirac/lbfgs_nocuda.c b/src/lib/Dirac/lbfgs_nocuda.c index b249024..a3c75b0 100644 --- a/src/lib/Dirac/lbfgs_nocuda.c +++ b/src/lib/Dirac/lbfgs_nocuda.c @@ -318,7 +318,7 @@ mult_hessian(int m, double *pk, double *gk, double *s, double *y, double *rho, i #endif exit(1); } - if ((idx=(int*)calloc((size_t)M,sizeof(double)))==0) { + if ((idx=(int*)calloc((size_t)M,sizeof(int)))==0) { #ifndef USE_MIC fprintf(stderr,"%s: %d: no free memory\n",__FILE__,__LINE__); #endif diff --git a/src/lib/Dirac/robust_lbfgs_nocuda.c b/src/lib/Dirac/robust_lbfgs_nocuda.c index 12b0018..78553e3 100644 --- a/src/lib/Dirac/robust_lbfgs_nocuda.c +++ b/src/lib/Dirac/robust_lbfgs_nocuda.c @@ -165,7 +165,7 @@ mult_hessian(int m, double *pk, double *gk, double *s, double *y, double *rho, i #endif exit(1); } - if ((idx=(int*)calloc((size_t)M,sizeof(double)))==0) { + if ((idx=(int*)calloc((size_t)M,sizeof(int)))==0) { #ifndef USE_MIC fprintf(stderr,"%s: %d: no free memory\n",__FILE__,__LINE__); #endif From d291d4402915eb04a49b522cfee1be739056cd09 Mon Sep 17 00:00:00 2001 From: Sarod Yatawatta Date: Tue, 27 Feb 2018 15:12:13 +0100 Subject: [PATCH 2/7] fixed missing free (pinv) --- src/lib/Radio/residual.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/Radio/residual.c b/src/lib/Radio/residual.c index 1f365b4..9f17705 100644 --- a/src/lib/Radio/residual.c +++ b/src/lib/Radio/residual.c @@ -1714,6 +1714,7 @@ predict_visibilities_multifreq_withsol(double *u,double *v,double *w,double *p,d pthread_attr_destroy(&attr); + if (pinv) free(pinv); free(th_array); free(threaddata); From 7d7b844c655a7467829b2cb7775dc211b563f4ec Mon Sep 17 00:00:00 2001 From: Sarod Yatawatta Date: Tue, 27 Feb 2018 15:31:56 +0100 Subject: [PATCH 3/7] clarify array access in fitsio --- src/restore/restore.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/restore/restore.c b/src/restore/restore.c index 7bd9dc7..d196ece 100644 --- a/src/restore/restore.c +++ b/src/restore/restore.c @@ -55,9 +55,10 @@ zero_image(long totalrows, long offset, long firstrow, long nrows, charp= (float *) fits_iter_get_array(&cols[0]); } - + /* NOTE: 1st element of array is the null pixel value! */ + /* Loop from 1 to nrows, not 0 to nrows - 1. */ for (ii = 1; ii <= nrows; ii++) { - charp[ii]=0.0; + charp[ii]=0.0; } return 0; @@ -1038,6 +1039,12 @@ int main(int argc, char **argv) { free(clusterfile); glist_delete(&slist); free(ignfile); + } else { + if (ffile) free(ffile); + if (slistname) free(slistname); + if (solfile) free(solfile); + if (clusterfile) free(clusterfile); + if (ignfile) free(ignfile); } return 0; } From dd094c317d7a045bbab16e09da03e4cc00731320 Mon Sep 17 00:00:00 2001 From: Sarod Yatawatta Date: Tue, 27 Feb 2018 16:09:22 +0100 Subject: [PATCH 4/7] fix invalid cases --- src/lib/Dirac/clmfit_nocuda.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/Dirac/clmfit_nocuda.c b/src/lib/Dirac/clmfit_nocuda.c index edd539a..a1f1185 100644 --- a/src/lib/Dirac/clmfit_nocuda.c +++ b/src/lib/Dirac/clmfit_nocuda.c @@ -878,7 +878,7 @@ mlm_der_single( printf("Singular matrix info=%d\n",status); #endif } - } else { + } else if (solve_axb==2) { /* SVD solver *********************************/ /* U S VT = A */ status=my_dgesvd('A','A',M,M,JkTJk,M,Sd,Ud,M,VTd,M,WORK,lwork); @@ -940,7 +940,7 @@ mlm_der_single( printf("Singular matrix info=%d\n",status); #endif } - } else { + } else if (solve_axb==2) { /* SVD solver *********************************/ /* dhatk <= U^T jacTed */ my_dgemv('T',M,M,1.0,Ud,M,JkTe,1,0.0,dhatk,1); From 068cf2322cd1ddc06026cb90a4cbbdcb8532776c Mon Sep 17 00:00:00 2001 From: Sarod Yatawatta Date: Tue, 27 Feb 2018 16:15:23 +0100 Subject: [PATCH 5/7] check int range --- src/lib/Radio/readsky.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib/Radio/readsky.c b/src/lib/Radio/readsky.c index f30553b..b340d41 100644 --- a/src/lib/Radio/readsky.c +++ b/src/lib/Radio/readsky.c @@ -686,8 +686,10 @@ printf("Nc=%d\n",Nc); memset(buf,0,buff_len); c=read_next_string(&buf,&buff_len,cfp); if (c!=1) { - /* first column is solution number (int) 1..8N */ + /* first column is solution number (int) 0..8N-1 */ sscanf(buf,"%d",&cn); + /* also do a sanity check */ + if ( cn<0 || cn>Nc ) cn=0; } #ifdef DEBUG printf("%d ",cn); From 578470f07d9f5b8af40674d47669c932ce6ff512 Mon Sep 17 00:00:00 2001 From: Sarod Yatawatta Date: Wed, 28 Feb 2018 10:02:27 +0100 Subject: [PATCH 6/7] fixed wrong size of memory allocation --- src/lib/Dirac/lbfgs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/Dirac/lbfgs.c b/src/lib/Dirac/lbfgs.c index d8ac3cc..2486dda 100644 --- a/src/lib/Dirac/lbfgs.c +++ b/src/lib/Dirac/lbfgs.c @@ -225,7 +225,7 @@ mult_hessian(int m, double *pk, double *gk, double *s, double *y, double *rho, i fprintf(stderr,"%s: %d: no free memory\n",__FILE__,__LINE__); exit(1); } - if ((idx=(int*)calloc((size_t)M,sizeof(double)))==0) { + if ((idx=(int*)calloc((size_t)M,sizeof(int)))==0) { fprintf(stderr,"%s: %d: no free memory\n",__FILE__,__LINE__); exit(1); } From 4bf20e77d14a61291f4dfa10c862b4986f5693ec Mon Sep 17 00:00:00 2001 From: Sarod Yatawatta Date: Wed, 28 Feb 2018 10:52:57 +0100 Subject: [PATCH 7/7] added cookbook link --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index 3c5e25b..a0614d7 100644 --- a/README.md +++ b/README.md @@ -156,3 +156,8 @@ Each 8 rows of any given column represent the 8 values of a 2x2 Jones matrix. Le When a luster has a chunk size > 1, there will be more than 1 solution per given time interval. So for this cluster, there will be more than 1 column in the solution file, the exact number of columns being equal to the chunk size. + + + +### Additional Info +See [LOFAR Cookbook Chapter](https://support.astron.nl/LOFARImagingCookbook/sagecal.html).