Allink  v0.1
Dinamica.cpp
00001 /***********************************************************************
00002 ElPoly:This progam provide a graphical visualisation of the data 
00003 opend by VarData using openGL glut. The most important option are 
00004 the possibility of changing the backfold of the polymers with 'c', 
00005 see the subsequent file in the list with '>', see the bond with 'b'. 
00006 Copyright (C) 2008 by Giovanni Marelli <sabeiro@virgilio.it>
00007 
00008 
00009 This program is free software; you can redistribute it and/or modify
00010 it under the terms of the GNU General Public License as published by
00011 the Free Software Foundation; either version 2 of the License, or
00012 (at your option) any later version.
00013 
00014 This program is distributed in the hope that it will be useful,
00015 but WITHOUT ANY WARRANTY; without even the implied warranty of
00016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017 GNU General Public License for more details.
00018 
00019 You should have received a copy of the GNU General Public License
00020 along with this program; if not, write to the Free Software
00021 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00022 ***********************************************************************/
00023 #include "Forces.h"
00024 #include <signal.h>
00025 #include <fenv.h>
00026 void Legenda();
00027 void Particle();
00028 void DrawParticle();
00029 void keyboard(unsigned char key,int x, int y);
00030 void InitConstant();
00031 Forces *Fm;
00032 static volatile int IfExit = 0;
00033 static int IfUser = 1;
00034 
00035 static void StopLoop(int sig)
00036 {
00037   IfExit = 1;
00038   printf("Loop stopped\n");
00039 }
00040 int main(int argc,char **argv){
00041   char Comando[50];
00042   char ConfFile[256];
00043   signal(SIGTSTP,StopLoop);
00044   signal(SIGSTOP,StopLoop);
00045   signal(SIGSTOP,StopLoop);
00046   //  frame = (char *)malloc(100*sizeof(char));
00047   //SpecFuntore <Matematica> SpecMat(&Mat,Matematica::Eval);
00048   //SpecFuntore <ElPoly> SpecPol(&Pol,ElPoly::ContactAngle);
00049   if(argc <2){ printf("ConfFile not specified\n"); return 1;}
00050   int NEdge = 20+1;
00051   //Fm->Solve();
00052   int *FilePos = (int *)calloc(argc,sizeof(int));
00053   int NFile = 0;
00054   char Snapshot[60];
00055   int InitFile = 0;
00056   //  ScaleUn = Fm->Gen->Edge[0];
00057   //Principal(argc,argv);
00058   for(int i=1;i<argc;i++){
00059     if(argv[i][0] != '-'){
00060       FilePos[NFile] = i;
00061       NFile++;
00062     }
00063     else if(!strcmp(*(argv+i),"-d")){
00064       sprintf(Comando,"d");
00065       IfUser = 0;
00066     }
00067     else if(!strcmp(*(argv+i),"-r")){
00068       sprintf(Comando,"r");
00069       IfUser = 0;
00070     }
00071     else if(!strcmp(*(argv+i),"-s")){
00072       sprintf(Comando,"s");
00073       IfUser = 0;
00074     }
00075     else if(!strcmp(*(argv+i),"-c")){
00076       if(argc > i){
00077    sprintf(ConfFile,"%s",argv[i+1]);
00078    i++;
00079       }
00080       else {
00081    printf("Missing config file\n");
00082       }
00083     }
00084     else if(!strcmp(*(argv+i),"-i")){
00085       if(argc > i){
00086    sprintf(Snapshot,"%s",*(argv+i+1));
00087    InitFile = i + 1;
00088       }
00089       else{
00090    printf("Snapshot file missing\n");
00091       }
00092     }
00093     else if(!strncmp(*(argv+i),"--",2)){
00094       sprintf(Comando,"%s",argv[i]+2);
00095       IfUser = 0;
00096     }
00097   }
00098   if(InitFile)
00099     Fm = new Forces(argc,argv,ConfFile,argv[InitFile]);
00100   else
00101     Fm = new Forces(argc,argv,NEdge,ConfFile);
00102   fedisableexcept(FE_ALL_EXCEPT);
00103   char cSystem1[STRSIZE];
00104   char cSystem2[STRSIZE];
00105   Fm->SysInfo(cSystem1);
00106   Fm->SysDef(cSystem2);
00107   printf("------------------------------------------------------\n");
00108   printf("%s NFile %d\n%s\n",cSystem1,NFile,cSystem2);
00109   printf("------------------------------------------------------\n");
00110   while(strcmp(Comando,"q")){
00111     if(IfUser){
00112       printf("Dinamica> ");
00113       scanf("%s",Comando);
00114     }
00115     if(!strcmp(Comando,"d")){
00116 #ifdef __glut_h__
00117       Fm->Graphics(argc,argv);
00118 #else 
00119       printf("Graphics libraries (GL/glut.h) not supplied\n");
00120 #endif //__glut_h__
00121       if(!IfUser) return 0;
00122     }
00123     else if(!strcmp(Comando,"s")){
00124       Fm->RunDynamics();
00125       if(!IfUser) return 0;      
00126     }
00127     else if(!strcmp(Comando,"r")){
00128       Fm->RunDynamics();
00129       if(!IfUser) return 0;
00130     }
00131     else if(!strcmp(Comando,"nrg")){
00132       for(int f=0;f<NFile;f++){
00133    fprintf(stderr,"Elaborating file %s %.3f %%\r",argv[FilePos[f]],f/(double)NFile*100.);
00134    Fm->CalcTotNrg(argv[FilePos[f]],f);
00135       }
00136       if(!IfUser) return 0;
00137     }
00138     else if(!strcmp(Comando,"PepNrg")){
00139       for(int f=0;f<NFile;f++){
00140    fprintf(stderr,"Elaborating file %s %.3f %%\r",argv[FilePos[f]],f/(double)NFile*100.);
00141    Fm->CalcNrgPep(argv[FilePos[f]],f);
00142       }
00143       if(!IfUser) return 0;
00144     }
00145     else if(!strcmp(Comando,"ExpPep")){
00146       Fm->ExplorePepSize();
00147       if(!IfUser) return 0;
00148     }
00149     else if(!strcmp(Comando,"ExpPep2d")){
00150       Fm->ExplorePepSize2d();
00151       if(!IfUser) return 0;
00152     }
00153     else if(!strcmp(Comando,"ExpDist")){
00154       Fm->ExploreDoubleMin();
00155       if(!IfUser) return 0;
00156     }
00157     else if(!strcmp(Comando,"Widom")){
00158       for(int f=0;f<NFile;f++){
00159    fprintf(stderr,"Elaborating file %s %.3f %%\r",argv[FilePos[f]],f/(double)NFile*100.);
00160    Fm->RunWidom(argv[FilePos[f]],f);
00161       }
00162       if(!IfUser) return 0;
00163     }
00164     else if(!strcmp(Comando,"WidomChIn")){
00165       for(int f=0;f<NFile;f++){
00166    fprintf(stderr,"Elaborating file %s %.3f %%\r",argv[FilePos[f]],f/(double)NFile*100.);
00167    Fm->RunWidomChIn(argv[FilePos[f]],f);
00168       }
00169       printf("\n");
00170       if(!IfUser) return 0;
00171     }
00172     else if(!strcmp(Comando,"WidomChOut")){
00173       for(int f=0;f<NFile;f++){
00174    fprintf(stderr,"Elaborating file %s %.3f %%\r",argv[FilePos[f]],f/(double)NFile*100.);
00175    Fm->RunWidomChOut(argv[FilePos[f]],f);
00176       }
00177       printf("\n");
00178       if(!IfUser) return 0;
00179     }
00180     else if(!strcmp(Comando,"Rosenbluth")){
00181       char File2Write[60];
00182       for(int f=0;f<NFile;f++){
00183    sprintf(File2Write,"Rosenbluth%05d.dat",f);
00184    FILE *WidomIn = fopen(File2Write,"w");
00185    fprintf(stderr,"Elaborating file %s %.3f %%\r",argv[FilePos[f]],f/(double)NFile*100.);
00186    Fm->ReOpen(argv[FilePos[f]],BF_PART);
00187    Fm->RosenIn(WidomIn);
00188    fclose(WidomIn);
00189       }
00190       printf("\n");
00191       if(!IfUser) return 0;
00192    }
00193     else if(!strcmp(Comando,"RosenOut")){
00194       char File2Write[60];
00195       for(int f=0;f<NFile;f++){
00196    sprintf(File2Write,"RosenOut%05d.dat",f);
00197    FILE *WidomIn = fopen(File2Write,"w");
00198    fprintf(stderr,"Elaborating file %s %.3f %%\r",argv[FilePos[f]],f/(double)NFile*100.);
00199    Fm->ReOpen(argv[FilePos[f]],BF_PART);
00200    Fm->RosenOut(WidomIn);
00201    fclose(WidomIn);
00202       }
00203       printf("\n");
00204       if(!IfUser) return 0;
00205    }
00206    else if(!strcmp(Comando,"Tens")){
00207      Fm->CalcTens(argv,FilePos,NFile);
00208      if(!IfUser) return 0;
00209    }
00210    else if(!strcmp(Comando,"AvForces")){
00211      Fm->AvForces(argv,FilePos,NFile);
00212      if(!IfUser) return 0;
00213    }
00214    else if(!strcmp(Comando,"Trial")){
00215      Fm->Trial();
00216      if(!IfUser) return 0;
00217    }
00218     else if(!strcmp(Comando,"?") ){
00219       Legenda();
00220     }
00221     else if(!strcmp(Comando,"!") ){
00222       printf("Insert a shell command: ");
00223       scanf("%s",Comando);
00224       system(Comando);
00225     }//-----------------System-Info---------------------------
00226     else if(!strcmp(Comando,"info")){
00227       printf("------------------------------------------------------\n");
00228       //printf("%s\n",Fm->SysInfo());
00229     }
00230     else if(!strcmp(Comando,"write") ){
00231       Fm->Write("ciccia.dat");
00232     }
00233     else if(!strcmp(Comando,"q") );
00234     else {
00235       IfUser = 1;
00236       printf("Comando non valido, scrivere ? per la lista dei comandi\n");
00237     }
00238   }
00239   printf("Te se qe te ve be te ne?\n");
00240   return 0;
00241 }
00242 #ifdef __glut_h__
00243 void ParticleList(){
00244   Fm->DrawScene();
00245 }
00246 // void ParticleRealTime(){
00247 //   //Fm->DrawNano();
00248 // }
00249 // void InitConstant(){
00250 //   Fm->InitConstant();
00251 // }
00252 void keyboard(unsigned char key,int x, int y){
00253   Fm->keyboard(key,x,y);
00254 }
00255 void Menu(){
00256   Fm->Menu();
00257 }
00258 void DynamicsMotion(){
00259   Fm->DynamicsView();
00260 }
00261 #endif
00262 void Legenda(){
00263   printf("\n\
00264 *****************************************************************\n\
00265 (                                                               )\n\
00266 )    Program that reads and elaborate a spefic file format      (\n\
00267 (    the option are the following, Needs a input file           )\n\
00268 )                                                               (\n\
00269 (-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-)\n\
00270 (   d     draw the 3D position of the particle                  )\n\
00271 (   ! execute a shell command                                   )\n\
00272 (   q    quit                                                   )\n\
00273 (   dens density of the [coord] coordinate for the [file]       )\n\
00274 (   pro calculate the projection long [coord]                   )\n\
00275 (   threshold set how many particle per cell will be considered )\n\
00276 (   surf ratio between the actual surcafe and the circular      )\n\
00277 (   core three dimentional sampled average of the system        )\n\
00278 (   diff diffusivity of the extra particle                      )\n\
00279 (   > <  open the file form the list position                   )\n\
00280 (   cm   movement  of the center of mass of the system          )\n\
00281 (   file number of file to use from the list                    )\n\
00282 (   info ...                                                    )\n\
00283 (   chbf change backfold                                        )\n\
00284 (   val  number of values for the density profile               )\n\
00285 *****************************************************************\n");
00286 }