      PROGRAM WASSI    
      
      COMMON/BASIC/NGRID,NYEAR,NLC,BYEAR,IYSTART,IYEND,POP_FLAG,REGION,
     &CLIMATE_FLAG
     
      COMMON/LANDCHANGE/FPERD, FOR_CONV_TO, LAI_CHG
      
      COMMON/CLIMATECHANGE/PPT_CHG,TEMP_CHG
      
      COMMON/GROUNDWATER/ GROUNDWATER(2200,9), GW_CHG  
      
      COMMON/DEMANDCHANGE/DOM_CHG, IND_CHG, IRR_CHG, LIV_CHG, MIN_CHG, 
     &THR_CHG, PUS_CHG, AQU_CHG, POP_CHG

      INTEGER IYEAR, IYSTART, IYEND, BYEAR
      
      INTEGER NLC, NGRID,POP_FLAG, FOR_CONV_TO
           
      INTEGER MONTHD(12),MONTHL(12)
      
      REAL FPERD, LAI_CHG
      
      REAL PPT_CHG, TEMP_CHG, GW_CHG
      
      REAL DOM_CHG, IND_CHG, IRR_CHG, LIV_CHG, MIN_CHG, THR_CHG,
     &PUS_CHG, AQU_CHG, POP_CHG

      CHARACTER*5 CLIMATE_FLAG
      
      CHARACTER*2 REGION
      
      CHARACTER*50 CLIM_DESC
      
      CHARACTER*50 POPDESC
      
      CHARACTER*20 FOR_CONV_DES
      

C -- GET USER ID (UID) FROM COMMAND LINE ARGUMENTS TO ALLOW MULTIPLE USERS RUNNING MODEL SIMULTANEOUSLY
C -- REQUIRED ADDING UNIX LIBRARY AND VAX/VMS LIBRARY IN COMPILER
C -- CONFIGURE-SET OPTIONS-TARGET:  CHECK UNIX AND VAX/VMS LIBRARIES
C -- ESTABLISH BASE PATH WHERE FILES ARE STORED

      
      CHARACTER*4 USERNAME
      
      CHARACTER*32 UID
      
      CHARACTER*25 BASE_PATH
      
      INTEGER NUMARG
      
      INTEGER IARGC
      

      NUMARG = IARGC( )
         
      CALL GETARG (1, USERNAME)
      
      CALL GETARG (2, UID )
      
C      USERNAME='SGCP'
      
C      UID='ABCDEFGHIJKLMNOPQRSTUVWXYZ123456'
            
      WRITE(*,1) USERNAME
      
1     FORMAT('USERNAME= ',A4/)

      WRITE(*,2) UID
      
2     FORMAT('UID= ',A32/)

      BASE_PATH='C:\WaSSI\WASSICB_WEB_2_1\'

C -- IF BASE PATH CHANGES, MUST CHANGE NUMBER OF CHARACTERS IN BASE_PATH DECLARATION
                
      
C --- Number of days for each month during regular year
      DATA MONTHD/31,28,31,30,31,30,31,31,30,31,30,31/

C --- Number of days for each month during leap year
      DATA MONTHL/31,29,31,30,31,30,31,31,30,31,30,31/
      
C --- Write introductory information to screen
      
      WRITE(*,10)
   10 FORMAT(' *************************************************'//,
     >    ' WaSSI Ecosystem Services Model'//,
     >    ' Eastern Forest Environmental Threat Assessment Center'/,
     >    ' USDA Forest Service Southern Research Station '/,
     >       ' Raleigh, NC'//,
     >       ' Version 2.1 -'//)

C--OPEN GENERAL.TXT INPUT FILE AND READ USER SELECTIONS FOR SIMULATION
    
      OPEN(1,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\GENERAL_'
     &//UID//'.TXT')
     
      CALL USERINPUT
      
C --IF USER SELECTS U.S. REGION, OPEN US INPUT FILES

      IF (REGION.EQ.'US') THEN     
     
         OPEN(2,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\INPUTS_US\
     &CELLINFO_US.TXT') 

         IF (CLIMATE_FLAG.EQ.'US_01') THEN
         
            OPEN(4,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_US\CLIMATE\PRISM_CLIMATE_US.TXT')
     
            CLIM_DESC='1960-2010 PRISM Historic Climate'
     
         ELSEIF (CLIMATE_FLAG.EQ.'US_02') THEN
         
            OPEN(4,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_US\CLIMATE\CSIROMK35A1B_CLIMATE_US.TXT')   
     
            CLIM_DESC='2001-2100 Csiromk35a1b Future Climate'      
     
         ELSEIF (CLIMATE_FLAG.EQ.'US_03') THEN
         
            OPEN(4,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_US\CLIMATE\MIROC32A1B_CLIMATE_US.TXT') 
     
            CLIM_DESC='2001-2100 Miroc32a1b Future Climate'   
     
         ELSEIF (CLIMATE_FLAG.EQ.'US_04') THEN
         
            OPEN(4,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_US\CLIMATE\CSIROMK2B2_CLIMATE_US.TXT')
     
            CLIM_DESC='2001-2100 Csiromk2b2 Future Climate' 
     
         ELSEIF (CLIMATE_FLAG.EQ.'US_05') THEN
         
            OPEN(4,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_US\CLIMATE\HADCM3B2_CLIMATE_US.TXT')
     
            CLIM_DESC='2001-2100 Hadcm3b2 Future Climate' 
     
         ELSEIF (CLIMATE_FLAG.EQ.'US_06') THEN
         
            OPEN(4,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_US\CLIMATE\CGCM3A1B_CLIMATE_US.TXT')
     
            CLIM_DESC='1960-2099 CGCM3A1B Future Climate' 
                     
          ELSEIF (CLIMATE_FLAG.EQ.'US_07') THEN
         
            OPEN(4,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_US\CLIMATE\CGCM3A2_CLIMATE_US.TXT')
     
            CLIM_DESC='1960-2099 CGCM3A2 Future Climate'    
            
         ELSEIF (CLIMATE_FLAG.EQ.'US_08') THEN
         
            OPEN(4,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_US\CLIMATE\CGCM3B1_CLIMATE_US.TXT')
     
            CLIM_DESC='1960-2099 CGCM3B1 Future Climate'              

         ELSEIF (CLIMATE_FLAG.EQ.'US_09') THEN
         
            OPEN(4,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_US\CLIMATE\CM2A1B_CLIMATE_US.TXT')
     
            CLIM_DESC='1960-2099 CM2A1B Future Climate'

         ELSEIF (CLIMATE_FLAG.EQ.'US_10') THEN
         
            OPEN(4,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_US\CLIMATE\CM2A2_CLIMATE_US.TXT')
     
            CLIM_DESC='1960-2099 CM2A2 Future Climate'
            
         ELSEIF (CLIMATE_FLAG.EQ.'US_11') THEN
         
            OPEN(4,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_US\CLIMATE\CM2B1_CLIMATE_US.TXT')
     
            CLIM_DESC='1960-2099 CM2B1 Future Climate'

         ELSEIF (CLIMATE_FLAG.EQ.'US_12') THEN
         
            OPEN(4,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_US\CLIMATE\HADCM3A1B_CLIMATE_US.TXT')
     
            CLIM_DESC='1960-2099 HADCM3A1B Future Climate'

         ELSEIF (CLIMATE_FLAG.EQ.'US_13') THEN
         
            OPEN(4,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_US\CLIMATE\HADCM3A2_CLIMATE_US.TXT')
     
            CLIM_DESC='1960-2099 HADCM3A2 Future Climate'  
            
         ELSEIF (CLIMATE_FLAG.EQ.'US_14') THEN
         
            OPEN(4,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_US\CLIMATE\HADCM3B1_CLIMATE_US.TXT')
     
            CLIM_DESC='1960-2099 HADCM3B1 Future Climate'            
                                                       
         ENDIF
     
         OPEN(7,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_US\SOILINFO_US.TXT')
         OPEN(8,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_US\LANDLAI_US.TXT')
         OPEN(11,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_US\HUCAREA_US.TXT')
         OPEN(12,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_US\HUCREGION_US.TXT') 
         OPEN(13,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_US\POPULATION_US.TXT')
         OPEN(14,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_US\GROUNDWATER_US.TXT')
         OPEN(15,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_US\RETURNFLOW_US.TXT')   
         OPEN(16,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_US\WATERUSE_US.TXT')
         OPEN(17,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_US\ROUTEMATRIX_US.TXT')
         OPEN(10,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_US\IMPERVIOUS_US.TXT')
       
         OPEN(77,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
     &OUTPUTS_US\BASICOUT_US_'//UID//'.TXT')
         OPEN(78,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
     &OUTPUTS_US\MONTHRUNOFF_US_'//UID//'.TXT')
         OPEN(79,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
     &OUTPUTS_US\ANNUALRUNOFF_US_'//UID//'.TXT')
         OPEN(80,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
     &OUTPUTS_US\AVGANNRUNOFF_US_'//UID//'.TXT')
         OPEN(81,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
     &OUTPUTS_US\ANNUALR_FACTOR_US_'//UID//'.TXT')     
         OPEN(82,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
     &OUTPUTS_US\AVGANNR_FACTOR_US_'//UID//'.TXT') 
         OPEN(100,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
     &OUTPUTS_US\MONTHWaSSI_US_'//UID//'.TXT')
         OPEN(200,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
     &OUTPUTS_US\ANNUALWaSSI_US_'//UID//'.TXT')      
         OPEN(300,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
     &OUTPUTS_US\AVGANNWaSSI_US_'//UID//'.TXT')
         OPEN(400,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
     &OUTPUTS_US\MONTHCARBON_US_'//UID//'.TXT')
         OPEN(500,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
     &OUTPUTS_US\ANNUALCARBON_US_'//UID//'.TXT')
         OPEN(600,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
     &OUTPUTS_US\AVGANNCARBON_US_'//UID//'.TXT')
c         OPEN(700,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
c     &OUTPUTS_US\ANNUALBIO_US_'//UID//'.TXT')
c         OPEN(800,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
c     &OUTPUTS_US\AVGANNBIO_US_'//UID//'.TXT')    
         OPEN(803,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
     &OUTPUTS_US\MOMEANRUNOFF_US_'//UID//'.TXT')  
         OPEN(804,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
     &OUTPUTS_US\MOMEANWASSI_US_'//UID//'.TXT')  
         OPEN(806,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
     &OUTPUTS_US\MOMEANCARBON_US_'//UID//'.TXT') 

     
C --IF USER SELECTS MEXICO REGION, OPEN MX INPUT FILES

      ELSEIF (REGION.EQ.'MX') THEN
      
         OPEN(2,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\INPUTS_MX\
     &CELLINFO_MX.TXT') 
     
         IF (CLIMATE_FLAG.EQ.'MX_01') THEN
         
            OPEN(4,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_MX\CLIMATE\CCA_UNAM_CLIMATE_MX.TXT')
     
            CLIM_DESC='1901-1984 CCA at UNAM Historic Climate' 
     
         ELSEIF (CLIMATE_FLAG.EQ.'MX_02') THEN
         
            OPEN(4,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_MX\CLIMATE\NCAR_CCSM3_A2_CLIMATE_MX.TXT')

            CLIM_DESC='2000-2099 NCAR CCSM3 A2 Future Climate' 
         
         ELSEIF (CLIMATE_FLAG.EQ.'MX_03') THEN

            OPEN(4,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_MX\CLIMATE\NCAR_CCSM3_A1B_CLIMATE_MX.TXT')
     
            CLIM_DESC='2000-2099 NCAR CCSM3 A1B Future Climate' 
         
         ELSEIF (CLIMATE_FLAG.EQ.'MX_04') THEN
         
            OPEN(4,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_MX\CLIMATE\NCAR_CCSM3_B1_CLIMATE_MX.TXT')     

            CLIM_DESC='2000-2099 NCAR CCSM3 B1 Future Climate'     

         ENDIF
     
     
         OPEN(7,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_MX\SOILINFO_MX.TXT')
         OPEN(8,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_MX\LANDLAI_MX.TXT')
 
      
         OPEN(77,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
     &OUTPUTS_MX\BASICOUT_MX_'//UID//'.TXT')
         OPEN(78,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
     &OUTPUTS_MX\MONTHRUNOFF_MX_'//UID//'.TXT')
         OPEN(79,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
     &OUTPUTS_MX\ANNUALRUNOFF_MX_'//UID//'.TXT')
         OPEN(80,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
     &OUTPUTS_MX\AVGANNRUNOFF_MX_'//UID//'.TXT')
         OPEN(81,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
     &OUTPUTS_MX\ANNUALR_FACTOR_MX_'//UID//'.TXT')     
         OPEN(82,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
     &OUTPUTS_MX\AVGANNR_FACTOR_MX_'//UID//'.TXT')      
         OPEN(400,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
     &OUTPUTS_MX\MONTHCARBON_MX_'//UID//'.TXT')
         OPEN(500,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
     &OUTPUTS_MX\ANNUALCARBON_MX_'//UID//'.TXT')
         OPEN(600,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
     &OUTPUTS_MX\AVGANNCARBON_MX_'//UID//'.TXT')
c         OPEN(700,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
c     &OUTPUTS_MX\ANNUALBIO_MX_'//UID//'.TXT')
c         OPEN(800,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
c     &OUTPUTS_MX\AVGANNBIO_MX_'//UID//'.TXT')  
         OPEN(803,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
     &OUTPUTS_MX\MOMEANRUNOFF_MX_'//UID//'.TXT')  
         OPEN(806,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
     &OUTPUTS_MX\MOMEANCARBON_MX_'//UID//'.TXT')        
      
      
C --IF USER SELECTS RWANDA REGION, OPEN RW INPUT FILES


      ELSEIF (REGION.EQ.'RW') THEN     
     
         OPEN(2,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\INPUTS_RW\
     &CELLINFO_RW.TXT') 

         IF (CLIMATE_FLAG.EQ.'RW_01') THEN
         
            OPEN(4,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_RW\CLIMATE\CRU31_CLIMATE_RW.TXT')
     
            CLIM_DESC='1960-2009 CRU3.1 Historic Climate'
     
         ELSEIF (CLIMATE_FLAG.EQ.'RW_02') THEN
         
            OPEN(4,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_RW\CLIMATE\CCCMA_CGCM3_A1B_RW.TXT')   
     
            CLIM_DESC='1960-2099 CCCMA CGCM3a1b Future Climate'      
     
         ELSEIF (CLIMATE_FLAG.EQ.'RW_03') THEN
         
            OPEN(4,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_RW\CLIMATE\CCCMA_CGCM3_A2_RW.TXT') 
     
            CLIM_DESC='1960-2099 CCCMA CGCM3a2 Future Climate'   

         ELSEIF (CLIMATE_FLAG.EQ.'RW_04') THEN
         
            OPEN(4,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_RW\CLIMATE\GFDL_CM2_A1B_RW.TXT') 
     
            CLIM_DESC='1960-2099 GFDL CM2a1b Future Climate'
            
         ELSEIF (CLIMATE_FLAG.EQ.'RW_05') THEN

            OPEN(4,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_RW\CLIMATE\GFDL_CM2_A2_RW.TXT') 
     
            CLIM_DESC='1960-2099 GFDL CM2a2 Future Climate'            
            
         ELSEIF (CLIMATE_FLAG.EQ.'RW_06') THEN

            OPEN(4,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_RW\CLIMATE\NCAR_CCSM3_A1B_RW.TXT') 
     
            CLIM_DESC='1960-2099 NCAR CCSM3a1b Future Climate' 
            
         ELSEIF (CLIMATE_FLAG.EQ.'RW_07') THEN

            OPEN(4,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_RW\CLIMATE\NCAR_CCSM3_A2_RW.TXT') 
     
            CLIM_DESC='1960-2099 NCAR CCSM3a2 Future Climate'            
            
         ELSEIF (CLIMATE_FLAG.EQ.'RW_08') THEN

            OPEN(4,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_RW\CLIMATE\UKMO_HADCM3_A1B_RW.TXT') 
     
            CLIM_DESC='1960-2099 UKMO HADCM3a1b Future Climate'            
            
         ELSEIF (CLIMATE_FLAG.EQ.'RW_09') THEN

            OPEN(4,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_RW\CLIMATE\UKMO_HADCM3_A2_RW.TXT') 
     
            CLIM_DESC='1960-2099 UKMO HADCM3a2 Future Climate'            
                       
         ENDIF
     
         OPEN(7,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_RW\SOILINFO_RW.TXT')
         OPEN(8,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_RW\LANDLAI_RW.TXT')
         OPEN(11,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_RW\HUCAREA_RW.TXT')
         OPEN(17,FILE=BASE_PATH//'USERS\'//USERNAME//'\Inputs\
     &INPUTS_RW\ROUTING_RW.TXT')
       
         OPEN(77,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
     &OUTPUTS_RW\BASICOUT_RW_'//UID//'.TXT')
         OPEN(78,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
     &OUTPUTS_RW\MONTHRUNOFF_RW_'//UID//'.TXT')
         OPEN(79,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
     &OUTPUTS_RW\ANNUALRUNOFF_RW_'//UID//'.TXT')
         OPEN(80,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
     &OUTPUTS_RW\AVGANNRUNOFF_RW_'//UID//'.TXT')
         OPEN(81,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
     &OUTPUTS_RW\ANNUALR_FACTOR_RW_'//UID//'.TXT')     
         OPEN(82,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
     &OUTPUTS_RW\AVGANNR_FACTOR_RW_'//UID//'.TXT') 
         OPEN(100,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
     &OUTPUTS_RW\MONTHWaSSI_RW_'//UID//'.TXT')
         OPEN(200,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
     &OUTPUTS_RW\ANNUALWaSSI_RW_'//UID//'.TXT')      
         OPEN(300,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
     &OUTPUTS_RW\AVGANNWaSSI_RW_'//UID//'.TXT')
         OPEN(400,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
     &OUTPUTS_RW\MONTHCARBON_RW_'//UID//'.TXT')
         OPEN(500,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
     &OUTPUTS_RW\ANNUALCARBON_RW_'//UID//'.TXT')
         OPEN(600,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
     &OUTPUTS_RW\AVGANNCARBON_RW_'//UID//'.TXT')
         OPEN(803,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
     &OUTPUTS_RW\MOMEANRUNOFF_RW_'//UID//'.TXT')  
         OPEN(804,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
     &OUTPUTS_RW\MOMEANWASSI_RW_'//UID//'.TXT')  
         OPEN(806,FILE=BASE_PATH//'USERS\'//USERNAME//'\Outputs\
     &OUTPUTS_RW\MOMEANCARBON_RW_'//UID//'.TXT') 

      ENDIF
      
C --- READ INPUT DATA FILES (WARMUP.FOR)

      WRITE(*,40)
40    FORMAT('  READING INPUT FILES AND USER SELECTIONS.....'///)

      CALL RPSDF
      CALL RPSINT
      CALL RPSCLIMATE
      CALL RPSLAI

C --- READ WATER USE AND ROUTING INPUT FILES FOR U.S. REGION IF SELECTED BY USER
      IF (REGION.EQ.'US') THEN
      
         CALL RPSWATERUSE  
         
      ENDIF
      
C --- WRITE USER SIMULATION SELECTIONS FOR VERIFICATION

      WRITE (*,31) 
      WRITE (77,31)
31    FORMAT('  GENERAL SIMULATION SELECTIONS'/)

      WRITE (*,32) REGION
      WRITE (77,32) REGION
32    FORMAT('  REGION:  ',A2/)

      WRITE (*,33) CLIM_DESC
      WRITE (77,33) CLIM_DESC      
33    FORMAT('  CLIMATE SCENARIO:  ',A50/)     

      WRITE (*,66) IYSTART
      WRITE (77,66) IYSTART      
66    FORMAT('  START YEAR:  ',I4/)  

      WRITE (*,67) IYEND
      WRITE (77,67) IYEND      
67    FORMAT('  END YEAR:  ',I4/)  

      WRITE (*,34) FPERD*100
      WRITE (77,34) FPERD*100
34    FORMAT('  FOREST LAND COVER REDUCTION:  ',F6.1,'%'/)

      IF(REGION.EQ.'US') THEN
      
      IF (FOR_CONV_TO.EQ.1) THEN
      
         FOR_CONV_DES='CROP'

      ELSEIF (FOR_CONV_TO.EQ.5) THEN
      
         FOR_CONV_DES='GRASSLAND'
         
      ELSEIF (FOR_CONV_TO.EQ.6) THEN
      
         FOR_CONV_DES='SHRUBLAND'
        
      ELSEIF (FOR_CONV_TO.EQ.7) THEN
      
         FOR_CONV_DES='WETLAND'

      ELSEIF (FOR_CONV_TO.EQ.8) THEN
      
         FOR_CONV_DES='WATER'

      ELSEIF (FOR_CONV_TO.EQ.9) THEN
      
         FOR_CONV_DES='URBAN'

      ELSEIF (FOR_CONV_TO.EQ.10) THEN
      
         FOR_CONV_DES='BARREN'

      ENDIF
      
      ENDIF
      
      IF(REGION.EQ.'MX')THEN
      
      IF (FOR_CONV_TO.EQ.1) THEN
      
         FOR_CONV_DES='CROP'

      ELSEIF (FOR_CONV_TO.EQ.5) THEN
      
         FOR_CONV_DES='GRASSLAND'
         
      ELSEIF (FOR_CONV_TO.EQ.6) THEN
      
         FOR_CONV_DES='SHRUBLAND'

      ELSEIF (FOR_CONV_TO.EQ.7) THEN
      
         FOR_CONV_DES='SAVANNA'

      ELSEIF (FOR_CONV_TO.EQ.8) THEN
      
         FOR_CONV_DES='WATER/URBAN/BARREN'
         
      ENDIF
      
      ENDIF
      
      IF(REGION.EQ.'RW')THEN

      IF (FOR_CONV_TO.EQ.1) THEN
      
         FOR_CONV_DES='CROP'
         
      ELSEIF (FOR_CONV_TO.EQ.5) THEN
      
         FOR_CONV_DES='GRASSLAND'

      ELSEIF (FOR_CONV_TO.EQ.6) THEN
      
         FOR_CONV_DES='SHRUBLAND'
         
      ENDIF
      
      ENDIF
      
      WRITE (*,35) FOR_CONV_DES 
      WRITE (77,35) FOR_CONV_DES     
35    FORMAT('  FOREST LAND COVER CONVERTED TO:  ',A20/)

      WRITE (*,36) LAI_CHG*100     
      WRITE (77,36) LAI_CHG*100  
36    FORMAT('  FOREST LAI CHANGE:  ',F6.1,'%'/)

      WRITE (*,37) PPT_CHG*100
      WRITE (77,37) PPT_CHG*100
37    FORMAT('  PRECIPITATION CHANGE:  ',F6.1,'%'/)
 
      WRITE (*,38) TEMP_CHG
      WRITE (77,38) TEMP_CHG
38    FORMAT('  TEMPERATURE CHANGE:  ',F6.1,' DEGREES C'///)
 

      IF (REGION.EQ.'US') THEN
      
         IF(POP_FLAG.EQ.8000) THEN
         
            POPDESC='TIME VARIABLE 2010-2060'
            
         ELSEIF(POP_FLAG.EQ.9000) THEN
         
            POPDESC='USE 2005 USGS DOMESTIC WATER USE DATA'
            
         ELSEIF(POP_FLAG.LT.8000) THEN
         
            WRITE(POPDESC,'(I4)') POP_FLAG
            
         ENDIF
         
         WRITE (*,42)
         WRITE (77,42)
42       FORMAT('  WATER SUPPLY AND DEMAND USER SIMULATION SELECTIONS'/)

         WRITE (*,39) POPDESC 
         WRITE (77,39) POPDESC
39       FORMAT('  POP SCENARIO FOR DOM WU CALCS:  ',A40/)

         WRITE (*,52) POP_CHG*100 
         WRITE (77,52) POP_CHG*100
52       FORMAT('  POPULATION CHANGE:  ',F6.1,'%'/)

         WRITE (*,41) GW_CHG*100
         WRITE (77,41) GW_CHG*100
41       FORMAT('  GROUNDWATER SUPPLY CHANGE:  ',F6.1,'%'/)

         WRITE (*,43) DOM_CHG*100
         WRITE (77,43) DOM_CHG*100
43       FORMAT('  DOMESTIC SECTOR WATER DEMAND CHANGE:  ',F6.1,'%'/)

         WRITE (*,44) IND_CHG*100
         WRITE (77,44) IND_CHG*100
44       FORMAT('  INDUSTRIAL SECTOR WATER DEMAND CHANGE:  ',F6.1,'%'/)

         WRITE (*,45) IRR_CHG*100
         WRITE (77,45) IRR_CHG*100
45       FORMAT('  IRRIGATION SECTOR WATER DEMAND CHANGE:  ',F6.1,'%'/)

         WRITE (*,46) LIV_CHG*100
         WRITE (77,46) LIV_CHG*100
46       FORMAT('  LIVESTOCK SECTOR WATER DEMAND CHANGE:  ',F6.1,'%'/)

         WRITE (*,47) MIN_CHG*100
         WRITE (77,47) MIN_CHG*100
47       FORMAT('  MINING SECTOR WATER DEMAND CHANGE:  ',F6.1,'%'/)

         WRITE (*,48) THR_CHG*100
         WRITE (77,48) THR_CHG*100
48       FORMAT('  THERMOPOWER SECTOR WATER DEMAND CHANGE:  ',F6.1,'%'/)

         WRITE (*,49) PUS_CHG*100
         WRITE (77,49) PUS_CHG*100
49       FORMAT('  PUBLIC SUPPLY SECTOR WATER DEMAND CHANGE:  ',F6.1,
     &'%'/)

         WRITE (*,50) AQU_CHG*100
         WRITE (77,50) AQU_CHG*100
50       FORMAT('  AQUACULTURE SECTOR WATER DEMAND CHANGE:  ',F6.1,
     &'%'///)

      ENDIF              

C--------------------------------------------------------------------------------------------      

C --- START SIMULATION LOOPS

      WRITE(*,51)
51    FORMAT('  COMPUTING MONTHLY WATER BALANCE.....'/)

      DO 200 ICELL=1, NGRID

C----START SIMULATION ONE YEAR PRIOR TO IYSTART (IYSTART-1) FOR MODEL WARM UP
                
         DO 300 IYEAR=((IYSTART-1)-BYEAR+1),(IYEND-BYEAR+1)
                  
             YEAR = BYEAR+IYEAR-1
             
C --- DETERMINE WHETHER YEAR IS A LEAP YEAR 
C --- http://www.timeanddate.com/date/leapyear.html

             IF (YEAR/4 .EQ. INT(YEAR/4)) THEN
             
                NDAY = 366
             
                IF (YEAR/100 .EQ. INT(YEAR/100)) THEN
                
                   NDAY = 365
                   
                   IF (YEAR/400 .EQ. INT(YEAR/400)) THEN
                   
                     NDAY = 366
                     
                   ENDIF
                   
                ENDIF
                
             ELSE
             
               NDAY = 365
               
             ENDIF
        

            DO 400 IM=1, 12
               
  
               IF (NDAY .EQ. 365) THEN
                 MNDAY=MONTHD(IM)
               ELSE
                 MNDAY=MONTHL(IM)
               ENDIF
                              
               CALL WARMPET(ICELL, IYEAR, IM, MNDAY)
               

               
                 
               CALL WATERBAL(ICELL, IYEAR, IM, MNDAY)
               


400         CONTINUE 
 
C     WRITE MONTHLY WATER BALANCE OUTPUT TO MONTHRUNOFF.TXT            
          
C     CALCULATE TOTAL ANNUAL RAIN, PET, AET, DISCHARGE, INT, SNOWP  
C     PRINT ANNUAL WATER BALANCE COMPONENTS TO ANNUALRUNOFF.TXT             


                       
            CALL OUTPUT(ICELL,IYEAR)

300      CONTINUE

C     CALCULATE AVERAGE WATER BALANCE COMPONENTS FROM IYSTART TO IYEND
C     WRITE TO AVGANNRUNOFF.TXT    
                                 
    
         CALL SUMMARY(ICELL)
         
200   CONTINUE
  

      IF (REGION.EQ.'US') THEN
      
      WRITE(*,60)
60    FORMAT('  ROUTING FLOW AND CALCULATING WASSI.....'/)

C     SIMULATE TOTAL FLOW FOR EACH MONTH AND EACH CELL                  
C     WRITE ACCUMULATED FLOW TO MONTHACCFLOW.TXT                       
C     PERFORM WATER SUPPLY/DEMAND AND WASSI CALCULATIONS               
C     WRITE WASSI OUTPUT TO ANNUALWaSSI.TXT                            
C     WRITE WASSI OUTPUT TO AVGANNWaSSI.TXT                               

            CALL FLOWROUTING_US
            
      ENDIF

      IF (REGION.EQ.'RW') THEN
      
      WRITE(*,61)
61    FORMAT('  ROUTING FLOW.....'/)

            CALL FLOWROUTING_RW
            
      ENDIF 
                 
C     Simulate GEP AND NEE for selected CELL                            
C     WRITE GEP AND NEE TO MONTHCARBON.TXT, ANNUALCARBON.TXT, AVGANNCARBON.TXT        
C     SIMULATE BIODIVERSITY FOR SELECTED CELL                           
C     WRITE BIODIVERSITY TO AVGANNBIO.TXT                                 

      WRITE(*,70)
70    FORMAT('  CALCULATING CARBON BALANCE.....'/)

            CALL CARBONBAL

      WRITE(*,80)
80    FORMAT('  SIMULATION COMPLETE'//)          

  
      STOP       
      END

