GLYLIB  0.3.0b
write_amber_prmtop.c
Go to the documentation of this file.
00001 /** \file write_amber_prmtop.c Writes out an amber prmtop file.
00002 
00003 There should be an amber_prmtop structure available that contains the proper
00004 information.  It is up to the calling function to make any needed modifications
00005 to that structure.  See also the read_amber_prmtop function.  The typical flow
00006 goes something like this:
00007 
00008  -# Read an amber prmtop file using read_amber_prmtop
00009         - The entire contents of the original file can be found in the void pointer.
00010                 See the documentation on use of the void pointer.
00011  -# Decide which parts to change and which parts of the original file to include
00012         in the output file.
00013         - Note that not all parts of the original file are necessarily parsed into
00014                 the assembly structure.  See parse_amber_prmtop for more info.
00015  -# Copy the updated prmtop contents to an amber_prmtop struct.  
00016         - It is probably safest to make a new amber-prmtop struct for the changed info.
00017         - If memory space is an issue, the information can be written back into the 
00018                 void pointer.  Alternately, and better, a new prmtop can be generated 
00019                 and the old one (in the void pointer) can be freed.
00020  -# Call this function to write an amber prmtop file out.
00021 
00022 Note, also, that the amber_prmtop struct contains content and formatting information.
00023 It is the duty of the calling program to get that right.  This function will provide
00024 only internal checks -- that it, it will make sure that the string lengths match the
00025 data information.  **But** it will get formatting information from the interpreted
00026 units in the amber_prmtop_section structure and -not- from the original formatting
00027 string.  **However** it will write the original string in *FORMAT out to the file. So,
00028 make sure there is a match.
00029 */
00030 
00031 #include <AMBER/amber.h>
00032 
00033 void write_amber_prmtop(fileset F, amber_prmtop *P){
00034 int wa=0,wb=0,wc=0,NCL=0;
00035 
00036 /// Open the file
00037 F.F=myfopen(F.N,"w");
00038 
00039 /// Write the version info
00040 fprintf(F.F,"%%VERSION %s\n",P[0].VERSION);
00041 
00042 /** Loop through all the sections 
00043         
00044         - Check that each string length matches the format length
00045         - Check that the number of units matches the length of the array **D
00046         - Write the required number per lie
00047         - Write the contents
00048 */
00049 for(wa=0;wa<P[0].nS;wa++){ // for each section found in the file
00050         fprintf(F.F,"%%FLAG %s\n",P[0].S[wa].N);
00051         fprintf(F.F,"%%FORMAT(%s)\n",P[0].S[wa].FORMAT);
00052         NCL=floor(P[0].S[wa].nt/P[0].S[wa].npl); // the number of full (complete) lines
00053         wc=0;
00054         for(wb=0;wb<NCL;wb++){ // write the complete lines
00055                 for(wc=wc;wc<P[0].S[wa].npl;wc++){ // each entry
00056                         if(strlen(P[0].S[wa].D[wc])!=P[0].S[wa].nc){mywhine("Improper format found in write_amber_prmtop");}
00057                         fprintf(F.F,"%s",P[0].S[wa].D[wc]);
00058                         }
00059                 fprintf(F.F,"\n");
00060                 }
00061         for(wc=wc;wc<P[0].S[wa].nt;wc++){ // write the last incomplete line
00062                 if(strlen(P[0].S[wa].D[wc])!=P[0].S[wa].nc){mywhine("Improper format found in write_amber_prmtop");}
00063                 fprintf(F.F,"%s",P[0].S[wa].D[wc]); 
00064                 }
00065         fprintf(F.F,"\n");
00066         } // close the loop over each section 
00067 fclose(F.F);
00068 return; 
00069 }
 All Classes Files Functions Variables Typedefs Defines