I am using a function in my program (windows compiler), which is here
Code:
void madrun_for_twiss(major_ip *ptr_major_ip, int *module_line_no, FILE *mad_call_file, int *err_index, FILE *fp_log)
{
*err_index=0;
int call_status;
fprintf(fp_log,"\n Header: mad_run; Fun: madrun_for_twiss -> TITLE is passed to madrun_for_twiss: %s",ptr_major_ip->title_line_name);
fprintf(fp_log,"\n Header: mad_run; Fun: madrun_for_twiss -> ASSIGN is passed to madrun_for_twiss: %s",ptr_major_ip->mad_assign_file);
fprintf(fp_log,"\n Header: mad_run; Fun: madrun_for_twiss -> LATTICE is passed to madrun_for_twiss: %s",ptr_major_ip->mad_lattice_file);
//FILE *mad_call_file=fopen("major_input.dat","w");
fprintf(mad_call_file,"\n TITLE,\"%s\"",ptr_major_ip->title_line_name);
fprintf(mad_call_file,"\n ASSIGN,PRINT=\"%s\"",ptr_major_ip->mad_assign_file);
fprintf(mad_call_file,"\n\n CALL, FILENAME=%s",ptr_major_ip->mad_lattice_file);
if(*(module_line_no+6) >= 0)fprintf(mad_call_file,"\n\n USE,%s,RANGE=#S/E",ptr_major_ip->use_line_name);
fprintf(mad_call_file,"\n PRINT,RANGE=#S/E");
/* Always use couple option */
fprintf(mad_call_file,"\n TWISS,DELTAP=0.000,COUPLE,SAVE=LATTICE");
fprintf(mad_call_file,"\n\n STOP");
fclose(mad_call_file);
fprintf(fp_log,"\n Header: mad_run; Fun: madrun_for_twiss -> MAD batch file called");
call_status=system("MAD8.BAT major_input.dat>mad_out_warning.txt");
return;
}
Here the statements in fprintf(mad_call_file,".....) also appears in file pointed by fp_log and file pointed by mad_call_file does not have any text written in it and program halts at statement fclose(mad_call_file). It appears that I can not close the file (which is opened in another function and is calling this function) in this function. But it is needed here, because I am running a batch file in next line using this file as an argument. Firstly I though that I could open the file pointed by mad_call_file in function itself, rather than passing FILE * from outside. But I do not know why program window disappears as program reaches to statement of mad_call_file=fopen("major_input.dat","w"); and this also did not work (this is presently commented). I could not understand why this is happening. Is the address pointed by two file pointers can create such problems? How I can solve this problem?
Thanks and regards...