Thread: Output of different files are mixing......Help needed

  1. #1
    Registered User
    Join Date
    Oct 2011
    Posts
    19

    Output of different files are mixing......Help needed

    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...

  2. #2
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    Well, without seeing how you call this function we really can't say. Perhaps you're doing something silly like passing fp_log in both places. If your program is just disappearing, I would guess that you have a seg fault or some such. We need more code to be sure.

  3. #3
    Registered User
    Join Date
    Oct 2011
    Posts
    19
    Thanks anduril,

    I was checking code again.... In function, which is calling the function "madrun_for_twiss", there is another section, in which memory allocation was wrong i.e. I was allocating less memory than required......I found this hint from you reply about seg fault, so that I checked for mainly memory allocation....


    Regards...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C++ overlapping output and adding extensions to output files
    By lordmorgul in forum Linux Programming
    Replies: 9
    Last Post: 05-11-2010, 08:26 AM
  2. Mixing stereo files?
    By Taper in forum C Programming
    Replies: 0
    Last Post: 01-10-2009, 08:14 AM
  3. Mixing wav files using ANSI C
    By crouchy8 in forum C Programming
    Replies: 15
    Last Post: 04-13-2008, 02:51 PM
  4. mixing two wav files n volume
    By sar in forum C++ Programming
    Replies: 3
    Last Post: 07-26-2004, 02:21 PM