From de7748b268c3ef7d2c6259e678282d1dc5d88e7e Mon Sep 17 00:00:00 2001 From: Nicolas Brouard Date: Wed, 11 Sep 2024 14:02:48 +0200 Subject: [PATCH] Still trying to run on Windows 11 using clang --- src/imach.c | 85 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 59 insertions(+), 26 deletions(-) diff --git a/src/imach.c b/src/imach.c index 9fa2988..a1c762d 100644 --- a/src/imach.c +++ b/src/imach.c @@ -1341,6 +1341,7 @@ Important routines #include #include #include +#include #else #include #endif @@ -1796,25 +1797,37 @@ static int split( char *path, char *dirc, char *name, char *ext, char *finame ) /* From a file name with (full) path (either Unix or Windows) we extract the directory (dirc) the name of the file (name), its extension only (ext) and its first part of the name (finame) */ - char *ss; /* pointer */ - int l1=0, l2=0; /* length counters */ + char *ss, *sso; /* pointer */ + int l1=0, l2=0, lss=0, lsso=0; /* length counters */ l1 = strlen(path ); /* length of path */ if ( l1 == 0 ) return( GLOCK_ERROR_NOPATH ); - ss= strrchr( path, DIRSEPARATOR ); /* find last / */ - if ( ss == NULL ) { /* no directory, so determine current directory */ + if((ss= strrchr( path, DIRSEPARATOR )) != NULL){/* find last of other / */ + lss=strlen(ss); + printf(" strlen lss=%d path=%s\n", lss, path); + } + while((sso= strrchr( path, ODIRSEPARATOR )) != NULL){ /* find last of other / */ + lsso=strlen(sso); + printf(" strlen lsso=%d OLDpath=%s\n", lsso, path); + path[l1-lsso]=DIRSEPARATOR; + printf(" strlen lsso=%d NEWpath=%s\n", lsso, path); + ss=sso; + printf(" NEWss=%s\n", ss); + } + fflush(stdout); + if ( ss == NULL ){ /* no directory, so determine current directory */ strcpy( name, path ); /* we got the fullname name because no directory */ /*if(strrchr(path, ODIRSEPARATOR )==NULL) printf("Warning you should use %s as a separator\n",DIRSEPARATOR);*/ /* get current working directory */ /* extern char* getcwd ( char *buf , int len);*/ #ifdef WIN32 - if (_getcwd( dirc, FILENAME_MAX ) == NULL ) { + if (_getcwd( dirc, FILENAME_MAX ) == NULL ) #else - if (getcwd(dirc, FILENAME_MAX) == NULL) { + if (getcwd(dirc, FILENAME_MAX) == NULL) #endif return( GLOCK_ERROR_GETCWD ); - } + /* got dirc from getcwd*/ printf(" DIRC = %s \n",dirc); } else { /* strip directory from path */ @@ -10157,6 +10170,7 @@ void printinggnuplot(char fileresu[], char optionfilefiname[], double ageminpar, fprintf(ficgp,"\nset out;unset log\n"); /* fprintf(ficgp,"\nset out \"%s.svg\"; replot; set out; # bug gnuplot",subdirf2(optionfilefiname,"ILK_")); */ + fprintf(ficlog," withing printinggnuplot\n");fflush(ficlog); strcpy(dirfileres,optionfilefiname); @@ -10309,7 +10323,8 @@ void printinggnuplot(char fileresu[], char optionfilefiname[], double ageminpar, /* } /\* k1 *\/ */ } /* cpt */ - + fprintf(ficlog," withing printinggnuplot 2 eme\n");fflush(ficlog); + /*2 eme*/ /* for (k1=1; k1<= m ; k1 ++){ */ for(nres=1; nres <= nresult; nres++){ /* For each resultline */ @@ -10425,6 +10440,7 @@ void printinggnuplot(char fileresu[], char optionfilefiname[], double ageminpar, } /* end nres */ /* } /\* k1 end 2 eme*\/ */ + fprintf(ficlog," withing printinggnuplot 3 eme\n");fflush(ficlog); /*3eme*/ /* for (k1=1; k1<= m ; k1 ++){ */ @@ -10485,6 +10501,7 @@ plot [%.f:%.f] \"%s\" every :::%d::%d u 1:%d t \"e%d1\" w l",ageminpar,fage,subd } } /* end nres */ /* } /\* end kl 3eme *\/ */ + fprintf(ficlog," withing printinggnuplot 4 eme\n");fflush(ficlog); /* 4eme */ /* Survival functions (period) from state i in state j by initial state i */ @@ -10543,6 +10560,7 @@ set ter svg size 640, 480\nunset log y\nplot [%.f:%.f] ", ageminpar, agemaxpar) } /* end cpt state*/ } /* end nres */ /* } /\* end covariate k1 *\/ */ + fprintf(ficlog," withing printinggnuplot 5 eme\n");fflush(ficlog); /* 5eme */ /* Survival functions (period) from state i in state j by final state j */ @@ -10610,6 +10628,7 @@ set ter svg size 640, 480\nunset log y\nplot [%.f:%.f] ", ageminpar, agemaxpar) /* } /\* end covariate *\/ */ } /* end nres */ + fprintf(ficlog," withing printinggnuplot 6 eme\n");fflush(ficlog); /* 6eme */ /* CV preval stable (period) for each covariate */ /* for (k1=1; k1<= m ; k1 ++) /\* For each covariate combination if any *\/ */ @@ -10666,6 +10685,7 @@ set ter svg size 640, 480\nunset log y\nplot [%.f:%.f] ", ageminpar, agemaxpar) } /* end cpt state*/ } /* end covariate */ + fprintf(ficlog," withing printinggnuplot 7 eme\n");fflush(ficlog); /* 7eme */ if(prevbcast == 1){ @@ -10728,6 +10748,7 @@ set ter svg size 640, 480\nunset log y\nplot [%.f:%.f] ", ageminpar, agemaxpar) } /* end cpt state*/ } /* end covariate */ } /* End if prevbcast */ + fprintf(ficlog," withing printinggnuplot 8 eme\n");fflush(ficlog); /* 8eme */ if(prevfcast==1){ @@ -11010,6 +11031,7 @@ set ter svg size 640, 480\nunset log y\nplot [%.f:%.f] ", ageminpar, agemaxpar) } /* end covariate */ } /* End if prevbcast */ + fprintf(ficlog," withing printinggnuplot92 eme\n");fflush(ficlog); /* 9eme writing MLE parameters */ fprintf(ficgp,"\n##############\n#9eme MLE estimated parameters\n#############\n"); @@ -11027,6 +11049,7 @@ set ter svg size 640, 480\nunset log y\nplot [%.f:%.f] ", ageminpar, agemaxpar) } } fprintf(ficgp,"##############\n#\n"); + fprintf(ficlog," withing printinggnuplot 10 eme\n");fflush(ficlog); /*goto avoid;*/ /* 10eme Graphics of probabilities or incidences using written MLE parameters */ @@ -11356,7 +11379,9 @@ set ter svg size 640, 480\nunset log y\nplot [%.f:%.f] ", ageminpar, agemaxpar) } /* end resultline */ } /* end ng */ /* avoid: */ - fflush(ficgp); + fflush(ficgp); + fprintf(ficlog," end printinggnuplot\n");fflush(ficlog); + } /* end gnuplot */ @@ -14903,8 +14928,7 @@ int main(int argc, char *argv[]) split(pathtot,path,optionfile,optionfilext,optionfilefiname); printf("\npathtot=%s,\npath=%s,\noptionfile=%s \noptionfilext=%s \noptionfilefiname=%s\n",pathtot,path,optionfile,optionfilext,optionfilefiname); #ifdef WIN32 - /*_chdir(path);*/ /* Can be a relative path */ - chdir(path); /* Can be a relative path */ + _chdir(path); /* Can be a relative path */ if(_getcwd(pathcd,MAXLINE) > 0) /* So pathcd is the full path */ #else chdir(path); /* Can be a relative path */ @@ -15750,8 +15774,7 @@ This file: %s
Title=%s
Datafile=%s strcpy(pathr,path); strcat(pathr,optionfilefiname); #ifdef WIN32 - /*_chdir(optionfilefiname);*/ /* Move to directory named optionfile */ - chdir(optionfilefiname); /* Move to directory named optionfile */ + _chdir(optionfilefiname); /* Move to directory named optionfile */ #else chdir(optionfilefiname); /* Move to directory named optionfile */ #endif @@ -16368,7 +16391,7 @@ Please run with mle=-1 to get a correct covariance matrix.\n",ageminpar,agemaxpa fprintf(ficres,"# agemin agemax for life expectancy, bage fage (if mle==0 ie no data nor Max likelihood).\n"); fprintf(ficres,"agemin=%.0f agemax=%.0f bage=%.0f fage=%.0f estepm=%d ftolpl=%e\n",ageminpar,agemaxpar,bage,fage, estepm, ftolpl); fprintf(ficparo,"agemin=%.0f agemax=%.0f bage=%.0f fage=%.0f estepm=%d, ftolpl=%e\n",ageminpar,agemaxpar,bage,fage, estepm, ftolpl); - + fflush(ficlog); /* Other stuffs, more or less useful */ while(fgets(line, MAXLINE, ficpar)) { /* If line starts with a # it is a comment */ @@ -16395,7 +16418,7 @@ Please run with mle=-1 to get a correct covariance matrix.\n",ageminpar,agemaxpa fprintf(ficres,"begin-prev-date=%.lf/%.lf/%.lf end-prev-date=%.lf/%.lf/%.lf mov_average=%d\n",jprev1, mprev1,anprev1,jprev2, mprev2,anprev2,mobilav); fprintf(ficlog,"begin-prev-date=%.lf/%.lf/%.lf end-prev-date=%.lf/%.lf/%.lf mov_average=%d\n",jprev1, mprev1,anprev1,jprev2, mprev2,anprev2,mobilav); } - + fflush(ficlog); while(fgets(line, MAXLINE, ficpar)) { /* If line starts with a # it is a comment */ if (line[0] == '#') { @@ -16409,7 +16432,7 @@ Please run with mle=-1 to get a correct covariance matrix.\n",ageminpar,agemaxpa break; } - + fflush(ficlog); dateprev1=anprev1+(mprev1-1)/12.+(jprev1-1)/365.; dateprev2=anprev2+(mprev2-1)/12.+(jprev2-1)/365.; @@ -16424,7 +16447,7 @@ Please run with mle=-1 to get a correct covariance matrix.\n",ageminpar,agemaxpa fprintf(ficparo,"pop_based=%d\n",popbased); fprintf(ficres,"pop_based=%d\n",popbased); } - + fflush(ficlog); /* Results */ /* Value of covariate in each resultine will be computed (if product) and sorted according to model rank */ /* It is precov[] because we need the varying age in order to compute the real cov[] of the model equation */ @@ -16519,7 +16542,7 @@ Please run with mle=-1 to get a correct covariance matrix.\n",ageminpar,agemaxpa fprintf(ficlog,"ERROR: Current version of IMaCh limits the number of resultlines to %d, you used %d\nYou can use the 'r' parameter file '%s' which uses option mle=0 to get other results. ",MAXRESULTLINESPONE-1,nresult,rfileres); goto end; } - + fflush(ficlog); if(!decoderesult(resultline, nresult)){ /* Fills TKresult[nresult] combination and Tresult[nresult][k4+1] combination values */ fprintf(ficparo,"result: %s\n",resultline); fprintf(ficres,"result: %s\n",resultline); @@ -16549,7 +16572,7 @@ Please run with mle=-1 to get a correct covariance matrix.\n",ageminpar,agemaxpa decoderesult(".",nresult ); /* No covariate */ } /* End switch parameterline */ }while(endishere==0); /* End do */ - + fflush(ficlog); /* freqsummary(fileres, agemin, agemax, s, agev, nlstate, imx,Tvaraff,nbcode, ncodemax,mint,anint); */ /* ,dateprev1,dateprev2,jprev1, mprev1,anprev1,jprev2, mprev2,anprev2); */ @@ -16595,13 +16618,13 @@ Please run with mle=-1 to get a correct covariance matrix.\n",ageminpar,agemaxpa datebackf=dateintmean-yrbproj; date2dmy(datebackf,&jbackf, &mbackf, &anbackf); } - + fprintf(ficlog," before printinggnuplot\n");fflush(ficlog); printinggnuplot(fileresu, optionfilefiname,ageminpar,agemaxpar,bage, fage, prevfcast, prevbcast, pathc,p, (int)anprojd-bage, (int)anbackd-fage);/* HERE valgrind Tvard*/ } printinghtml(fileresu,title,datafile, firstpass, lastpass, stepm, weightopt, \ model,imx,jmin,jmax,jmean,rfileres,popforecast,mobilav,prevfcast,mobilavproj,prevbcast, estepm, \ jprev1,mprev1,anprev1,dateprev1, dateprojd, datebackd,jprev2,mprev2,anprev2,dateprev2,dateprojf, datebackf); - + fprintf(ficlog," after printinghtml\n");fflush(ficlog); /*------------ free_vector -------------*/ /* chdir(path); */ @@ -16619,6 +16642,7 @@ Please run with mle=-1 to get a correct covariance matrix.\n",ageminpar,agemaxpa /* Other results (useful)*/ + fprintf(ficlog," before prevalence_limit\n");fflush(ficlog); /*--------------- Prevalence limit (period or stable prevalence) --------------*/ /*#include "prevlim.h"*/ /* Use ficrespl, ficlog */ @@ -17158,9 +17182,9 @@ Please run with mle=-1 to get a correct covariance matrix.\n",ageminpar,agemaxpa printf("Before Current directory %s!\n",pathcd); #ifdef WIN32 - /* if (_chdir(pathcd) != 0) */ - if (chdir(pathcd) != 0) + if (_chdir(pathcd) != 0) printf("Can't move to directory %s!\n",path); + /*if(_getcwd(pathcd,MAXLINE) > 0)*/ if(_getcwd(pathcd,MAXLINE) > 0) #else if(chdir(pathcd) != 0) @@ -17171,7 +17195,9 @@ Please run with mle=-1 to get a correct covariance matrix.\n",ageminpar,agemaxpa /*strcat(plotcmd,CHARSEPARATOR);*/ sprintf(plotcmd,"gnuplot"); #ifdef _WIN32 - sprintf(plotcmd,"\"%sgnuplot.exe\"",pathimach); + sprintf(plotcmd,"\"gnuplot.exe\""); + /*sprintf(plotcmd,"\"%sgnuplot.exe\"",pathimach);*/ /* If gnuplot is in the path */ + printf(" Win32 plotcmd=%s\n",plotcmd); #endif if(!stat(plotcmd,&info)){ printf("Error or gnuplot program not found: '%s'\n",plotcmd);fflush(stdout); @@ -17179,12 +17205,15 @@ Please run with mle=-1 to get a correct covariance matrix.\n",ageminpar,agemaxpa printf("Error or gnuplot program not found: '%s' Environment GNUPLOTBIN not set.\n",plotcmd);fflush(stdout); }else strcpy(pplotcmd,plotcmd); -#ifdef __unix + /* was __unix */ +#ifdef __UNIX strcpy(plotcmd,GNUPLOTPROGRAM); if(!stat(plotcmd,&info)){ printf("Error gnuplot program not found: '%s'\n",plotcmd);fflush(stdout); - }else + }else{ strcpy(pplotcmd,plotcmd); + } + printf(" _unix pplotcmd=%s\n",pplotcmd); #endif }else strcpy(pplotcmd,plotcmd); @@ -17196,7 +17225,11 @@ Please run with mle=-1 to get a correct covariance matrix.\n",ageminpar,agemaxpa if((outcmd=system(plotcmd)) != 0){ printf("Error in gnuplot, command might not be in your path: '%s', err=%d\n", plotcmd, outcmd); printf("\n Trying if gnuplot resides on the same directory that IMaCh\n"); +#ifdef _WIN32 + sprintf(plotcmd,"%sgnuplot.exe %s", pathimach, optionfilegnuplot); +#else sprintf(plotcmd,"%sgnuplot %s", pathimach, optionfilegnuplot); +#endif if((outcmd=system(plotcmd)) != 0){ printf("\n Still a problem with gnuplot command %s, err=%d\n", plotcmd, outcmd); strcpy(plotcmd,pplotcmd); -- 2.43.0