MAIN.f90 10.1 KB

!=============================================================================

!                              MAIN PROGRAM

!Here is the main time loop and the path/name for output files.


!=============================================================================

        program MAIN
        
        USE global_parameter                                    !module for shared parameter
        CALL read_namelist                                      !read the namelist for parameter values
        CALL allocation                                         !allocate arrays



!_____________________________________________________________________________
!                               OUTPUT FILES
!_____________________________________________________________________________

        root='output/'//trim(name_exp)                          !create output directory 
        open(25,file='src/tmp.txt')                             !        
        write(25,*)trim(root)                                   !
        close(25)                                               !        
        CALL system('src/OUT_DIR.sh')                           !        


        radiation=trim(root)//'/LIGHT_PROFILE.dat'              !light
        conc_euler=trim(root)//'/EULER_BIOMASS.dat'             !eulerian biomass
        binnedweight=trim(root)//'/LAGRANGE_BIOMASS.dat'        !lagrangian biomass
        nutlagrange=trim(root)//'/LAGRANGE_NUTRIENTS.dat'       !lagrangian nutrient profile
        nuteuler=trim(root)//'/EULER_NUTRIENTS.dat'             !eulerian nutrient profile
        growth_eul=trim(root)//'/EULER_GROWTHRATE.dat'          !eulerian growth rate
        growth_lag=trim(root)//'/LAGRANGE_GROWTHRATE.dat'       !lagrangiangrowth rate
        Qeuler=trim(root)//'/EULER_CELL_QUOTA.dat'              !eulerian cell quota
        Qlagrange=trim(root)//'/LAGRANGE_CELL_QUOTA.dat'        !lagrangian cell quota
        turb=trim(root)//'/DIFFUSIVITY.dat'                     !diffusivity profile
        depth_vector=trim(root)//'/DEPTH.dat'                    !time vector
        time_vector=trim(root)//'/TIME.dat'                    !depth vector


        open(12,file=conc_euler)                                !open output files
        open(13,file=radiation)                                 !
        open(16,file=binnedweight)                              !
        open(17,file=nutlagrange)                               !        
        open(18,file=nuteuler)                                  !
        open(21,file=turb)                                      !        
        open(31,file=Qeuler)                                    !       
        open(32,file=Qlagrange)                                 !
        open(33,file=growth_eul)                                !
        open(34,file=growth_lag)                                !
        open(35,file=time_vector)
        open(36,file=depth_vector)


!______________________________________________________________________________
!                              DISPLAY STARTING MESSAGE
!______________________________________________________________________________


        write(*,*) ' '
        write(*,*) ' '
        write(*,*) '_____________________________________________________________'
        write(*,*) ' '
        write(*,*) '          WELCOME TO THE LAGRANGIAN MODEL 2014'
        write(*,*) '____________________________________________________________ '
        write(*,*) ' '



        if (mix_state.eq.2) then
        write(*,*) '______________________________________________________________ '
        write(*,*) ' '
        write(*,*) 'DIFFUSIVITY CALCULATION FROM GOTM STARTING...WAIT'
        write(*,*) '______________________________________________________________ '
        write(*,*) ' '

        CALL system('cd gotm/ ; sleep 2s ;./gotm_prod_IFORT ; cd ..')
        end if

        write(*,*)'TIME LOOP STARTING...WAIT'
        write(*,*) ' '



!_________________________________________________________________________________
!                               START MODEL COMPUTATION
!_________________________________________________________________________________


        CALL general                                            !construct the grid and the diffusivity profile
        CALL initialization                                     !initializes variables


        write(12,*) euler                                       !write initial conditions in output files
        write(16,*) binned_weight/dz                            !
        write(17,*) N_lag                                       !
        write(18,*) N_euler                                     !
        write(21,*) Clquot_ACC!K                                           !
        write(31,*) Ncell/euler                                     !
        write(32,*) binned_Qlag                                 !
        write(33,*) grow                                        !
        write(34,*) binned_growth                               !
        Q_distrib2(:,:,1)=0d0
        i=2
        do time=1,nsteps                                        !START THE TIME LOOP!


                if (mix_state.eq.2) then                        !interpolate diffusivity profile from gotm to the model grid
                CALL INTERP_DIFF_PROF                           !
                end if                                          !
                CALL daylight                                   !compute the incident light
                CALL rdm_walk                                   !perform the random walk
                if (bio_calc.eq.1) then                         !
                CALL light_growth                               !lagrangian growth
                CALL bio_euler                                  !eulerian growth
                end if
                CALL ADV_DIFF                                   !compute advection and diffusion in a eulerian way
             

 
                if (mod(time,output_time).eq.0) then            !write outputs each output_time 
                                                                !
                write(21,*) Clquot_ACC!K                                   !
                write(13,*) CL/euler!rad                                 !
                write(16,*) binned_weight/dz                    !
                write(34,*) binned_growth                       !
                write(12,*) euler                               !
                write(17,*) N_lag                               !
                write(18,*) N_euler                             !
                write(33,*) grow                                !
                if(bio_model.ge.2) then                         !
                write(32,*) binned_Qlag                         !
                write(31,*) Ncell/euler                             !
                Q_distrib2(:,:,i)=Q_distrib
                growth_distrib2(:,:,i)=growth_distrib
                if(bio_model.eq.3) then
                 q_dist2(:,:,i)=q_dist
                mu_dist2(:,:,i)=mu_dist
                end if
                i=i+1
                end if                                          !
                                                                !
                end if                                          !



                Nut_taken(1:Nbin)=0d0                           !reinitialize binned arrays for lagrangian calculations
                binned_pos(1:Nbin)=0d0                          !        
                binned_Qlag(1:Nbin)=0d0                         !
                binned_growth(1:Nbin)=0d0                       !
                binned_weight(1:Nbin)=0d0                       !
                Q_distrib=0d0
                growth_distrib=0d0

                CALL clock                                      !display the time of the simulation

        end do                                                  !END OF THE TIME LOOP!


                write(35,*)time_vec
                write(36,*)levels(1:Nlevel-1)
                CALL write_output

        close(21)                                               ! close output files
        close(13)                                               !
        close(16)                                               !
        close(34)                                               !
        close(12)                                               !
        close(17)                                               !
        close(18)                                               !
        close(33)                                               !
        close(32)                                               !
        close(31)                                               !
        

!__________________________________________________________________________________
!                               DISPLAY END MESSAGE
!__________________________________________________________________________________
        write(*,*)'END'
        write(*,*) ' '
        write(*,*)'COMPUTATION SUCCESSFUL!'
        write(*,*) ' '
        write(*,*) '_________________'
        write(*,*) '  OUTPUT FILES:  '
        write(*,*) '_________________'
        write(*,*) ' '

        write(*,*) conc_euler
        write(*,*) nuteuler
        write(*,*) nutlagrange
        write(*,*) radiation
        write(*,*) turb
        write(*,*) binnedweight
        write(*,*) growth_eul
        write(*,*)growth_lag
        if(bio_model.eq.2) then
        write(*,*) Qeuler
        write(*,*) Qlagrange
        end if





        contains
!==================================================================================
        subroutine clock

        USE global_parameter

        if (mod(time,nsteps_hr/60).eq.0) then
        minute=minute+1
        end if

        if (mod(time,nsteps_hr).eq.0) then
        hour=hour+1
        if (mod(time,nsteps_d).eq.0) then
        hour=0
        minute=0
        day=day+1  
        end if
        write(*,*) 'Hour ',hour,' of day ',day,' completed!','  number particles=',nbpart
        end if

        end subroutine clock
!=================================================================================
        end program MAIN