#include <io.h>
#include <windows.h>
#include <tchar.h>
+#include <direct.h>
#else
#include <unistd.h>
#endif
/* 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 */
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);
/* } /\* 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 */
} /* end nres */
/* } /\* k1 end 2 eme*\/ */
+ fprintf(ficlog," withing printinggnuplot 3 eme\n");fflush(ficlog);
/*3eme*/
/* for (k1=1; k1<= m ; k1 ++){ */
}
} /* 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 */
} /* 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 */
/* } /\* 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 *\/ */
} /* end cpt state*/
} /* end covariate */
+ fprintf(ficlog," withing printinggnuplot 7 eme\n");fflush(ficlog);
/* 7eme */
if(prevbcast == 1){
} /* end cpt state*/
} /* end covariate */
} /* End if prevbcast */
+ fprintf(ficlog," withing printinggnuplot 8 eme\n");fflush(ficlog);
/* 8eme */
if(prevfcast==1){
} /* 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");
}
}
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 */
} /* end resultline */
} /* end ng */
/* avoid: */
- fflush(ficgp);
+ fflush(ficgp);
+ fprintf(ficlog," end printinggnuplot\n");fflush(ficlog);
+
} /* end gnuplot */
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 */
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
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 */
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] == '#') {
break;
}
-
+ fflush(ficlog);
dateprev1=anprev1+(mprev1-1)/12.+(jprev1-1)/365.;
dateprev2=anprev2+(mprev2-1)/12.+(jprev2-1)/365.;
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 */
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);
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); */
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); */
/* Other results (useful)*/
+ fprintf(ficlog," before prevalence_limit\n");fflush(ficlog);
/*--------------- Prevalence limit (period or stable prevalence) --------------*/
/*#include "prevlim.h"*/ /* Use ficrespl, ficlog */
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)
/*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);
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);
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);