Ecological Landscape Modeling: Models Pages

MultiRun.c

Go to the documentation of this file.
00001 
00016 /* General notes on revisions to this source file. 
00017        Feb 2005 v2.4.0 initial development
00018         
00019 */
00020 
00021 
00022 #include "multi_run.h"
00023 
00024 
00032 int numRuns(int SParmNum, int NumSRunsPerSet)
00033 {
00034    int numberRuns;
00035       
00036    numberRuns = (1+NumSRunsPerSet*SParmNum);
00037         
00038    return numberRuns;
00039 }
00040 
00055 int SensiParm_list(char* sparm_name) 
00056 {
00057    FILE *SParm_listFile;
00058    char filename[20];
00059    char modelFileName[300];
00060    char ss[422], *line;
00061    int SParmNum = 0;
00062    
00063    if (strcmp(sparm_name,"ALL")!=0) return(1) ;
00064    
00065    sprintf(filename,"SensiParm_list"); 
00066    sprintf( modelFileName, "%s/%s/Data/%s", ModelPath, ProjName, filename );
00067 
00068 /* Open file with list of parameters for Sensitivity Analysis */
00069  if ( ( SParm_listFile = fopen( modelFileName, "r" ) ) ==  NULL )
00070  {
00071      printf( "Can't open %s file!\n", modelFileName ) ;
00072      exit(-1) ;
00073  }
00074 
00075     sprintf(msgStr, "Sensitivity Analysis Parameters: ") ;
00076     WriteMsg(msgStr,1); 
00077     usrErr(msgStr);
00078    
00079     fgets( ss, 420, SParm_listFile );
00080     fgets( ss, 420, SParm_listFile ); 
00081     fgets( ss, 420, SParm_listFile ); /* skip header lines */
00082    
00083     while ( fgets( ss, 420, SParm_listFile ) != NULL && !feof( SParm_listFile ) )
00084     {
00085                 /* Allocate memory  for next parm set (initially, we have already gotten the info for the nominal run into the struct w/ SParmNum = 0) */
00086     if ( (ProgExec = ( ProgAttr *) malloc( (size_t) sizeof( ProgAttr ))) == NULL ) {
00087         sprintf(msgStr, "Failed to allocate memory for next struct defining multiple simulation runs.\n ") ;
00088         usrErr(msgStr);
00089         exit( -2 ) ;
00090     }
00091         line = ss;
00092         sscanf (line, "%s", &ProgExec->S_ParmName);
00093 
00094         SParmNum++; /* count the number of parms to be evaluated in sensi */
00095         RunList[SParmNum] = ProgExec;
00096         ProgExec->S_ParmRelVal = 0; /* init to 0 for all */
00097         
00098         sprintf(msgStr, "%d: %s", SParmNum, ProgExec->S_ParmName) ;
00099         WriteMsg(msgStr,1); 
00100         usrErr(msgStr);
00101     
00102 
00103      
00104     } /* end of reading basin lines */
00105     
00106     fclose(SParm_listFile);
00107     return (SParmNum);
00108 
00109 }
00110 
00111 
00116 void alloc_mem_runs(int SParmNum) 
00117 {
00118     if ( (ProgExec = ( ProgAttr *) malloc( (size_t) sizeof( ProgAttr ))) == NULL ) {
00119         sprintf(msgStr, "Failed to allocate memory for first struct defining (possibly multiple) simulation run(s).\n ") ;
00120         usrErr(msgStr);
00121         exit( -2 ) ;
00122     }
00123         /* allocate memory for array of pointers to simulation run attributes */
00124     if ( (RunList = ( ProgAttr **) malloc( (size_t) sizeof( ProgAttr *) * (SParmNum+1) ) ) == NULL )
00125     {
00126         printf( "Failed to allocate memory for RunList of simulation attributes \n " ); 
00127         exit( -2 );
00128     }
00129 
00130 
00131 }
00132 
00133 /****************************************************************************/
00134 

Generated on Sat Jan 7 14:04:15 2012 for ELM source code by  doxygen 1.5.6