Commit afa1bb4f authored by HOURDIN Christophe's avatar HOURDIN Christophe
Browse files

create branch asap_v1.00 - remake Steph ASAP2020 1985M1 2tsp with croco_locean...

create branch asap_v1.00 - remake Steph ASAP2020 1985M1 2tsp with croco_locean v1.00 in pulsation's Env without partit/ncjoin
parent a707c8b1
! $Id: online_bulk_var.F 1458 2014-02-03 15:01:25Z gcambon $
!
!======================================================================
! CROCO is a branch of ROMS developped at IRD and INRIA, in France
! The two other branches from UCLA (Shchepetkin et al)
! and Rutgers University (Arango et al) are under MIT/X style license.
! CROCO specific routines (nesting) are under CeCILL-C license.
!
! CROCO website : http://www.croco-ocean.org
!======================================================================
!
!
! This is the "online_bulk_var.F" script
!------------------------------------------------------------------------------
! This file contains the subfunctions enabling the specificatin of the files
! names and variables names for the online NCEP/CFSR tool:
!------------------------------------------------------------------------------
#include "cppdefs.h"
#if defined BULK_FLUX
#if defined ONLINE /* JG ONLINE */
!*******************************************************************************
subroutine get_bulknetcdf_names(bvar)
!------------------------------------------------------------------------------
! This subfunction specify the path and netcdf file name of the forcing field
! used to ensure the online bulk forcing in the online NCEP/CFSR tool. This
! name depends on the considered variable as well as the year (Y) and the month
! (M) of the ongoing computation
!------------------------------------------------------------------------------
! The names are adapted using:
! - the path name: pathbulk
! - the variable name: blk_vname(1,bvar)
! - the year Y: bulkyear
! - the month M: bulkmonth1/2
!
! INPUT
! bvar (index of the considered variable)
! OUTPUT
! bulkfilename(bvar) (path and file name of the considered variable)
implicit none
# include "param.h"
# include "online.h"
integer, intent(in) :: bvar
character bulkyear*4, bulkmonth1*1, bulkmonth2*2
integer lenstr
! If first iteration, Y and M from roms.in file
if(itbulkO(bvar).eq.0) then
bulkyearnum(bvar)=yearnum
bulkmonthnum(bvar)=monthnum
endif
! Variable to add the year in the name
write(unit=bulkyear,fmt='(I4)') bulkyearnum(bvar)
if(bulkmonthnum(bvar).lt.10) then
! Variable to add the month in the name (month<10)
write(unit=bulkmonth1,fmt='(I1)') bulkmonthnum(bvar)
! Filename
bulkfilename(bvar)=pathbulk(1:lenstr(pathbulk))//
& blk_vname(1,bvar)(1:lenstr(blk_vname(1,bvar)))//
& '_Y'//bulkyear//'M'//bulkmonth1//'.nc'
else
! Variable to add the mont in the name (month>10)
write(unit=bulkmonth2,fmt='(I2)') bulkmonthnum(bvar)
! Filename
bulkfilename(bvar)=pathbulk(1:lenstr(pathbulk))//
& blk_vname(1,bvar)(1:lenstr(blk_vname(1,bvar)))//
& '_Y'//bulkyear//'M'//bulkmonth2//'.nc'
endif
# ifdef AROME
bulkfilename(bvar)=pathbulk(1:lenstr(pathbulk))
#endif
return
end
!*******************************************************************************
subroutine get_bulkvar_names
!------------------------------------------------------------------------------
! This subfunction specify the variables names and caracteristics associated
! with the various forcing fields used to generate online bulk forcing in the
! online NCEP/CFSR tool:
!------------------------------------------------------------------------------
! For each variable:
! - blk_vname(1,X)=netcdf variable name
! - blk_vname(2,X)=details regarding the variable
! - blk_vname(3,X)=units of the variable
! - blk_vname(4,X)=?????
!
! OUTPUT
! Variables names and characteristics in "blk_vname"
implicit none
# include "param.h"
# include "online.h"
# ifdef AROME
! Temperature_height_above_ground
blk_vname(1,1)='t2m '
blk_vname(2,1)='Temperature '
blk_vname(3,1)='Kelvin '
blk_vname(4,1)='?????? '
! Specific_humidity
blk_vname(1,2)='rh '
blk_vname(2,2)='Specific Humidity at surface '
blk_vname(3,2)='Kg/Kg '
blk_vname(4,2)='?????? '
! Precipitation_rate
blk_vname(1,3)='rain '
blk_vname(2,3)='Precipitation_rate '
blk_vname(3,3)='kg/m^2/s '
blk_vname(4,3)='?????? '
! Downward_Short-Wave_Rad_Flux_surface
blk_vname(1,4)='xxx '
blk_vname(2,4)='xxx '
blk_vname(3,4)='W/m^2 '
blk_vname(4,4)='?????? '
! Net short_Rad_Flux_surface
blk_vname(1,5)='swhf '
blk_vname(2,5)='NET SHORT WAVE '
blk_vname(3,5)='W/m^2 '
blk_vname(4,5)='?????? '
! Downward_Long-Wave_Rad_Flux
blk_vname(1,6)='lwhf '
blk_vname(2,6)='Downward_Long-Wave_Rad_Flux '
blk_vname(3,6)='W/m^2 '
blk_vname(4,6)='?????? '
! Upward_Long-Wave_Rad_Flux_surface
blk_vname(1,7)='NOPE '
blk_vname(2,7)='?????? '
blk_vname(3,7)='W/m^2 '
blk_vname(4,7)='?????? '
! U-component_of_wind
blk_vname(1,8)='u10m '
blk_vname(2,8)='v10m '
blk_vname(3,8)='m/s '
blk_vname(4,8)='?????? '
! V-component_of_wind
blk_vname(1,9)='v10m '
blk_vname(2,9)='v10m '
blk_vname(3,9)='m/s '
blk_vname(4,9)='?????? '
# ifdef READ_PATM
! Atm pressure
blk_vname(1,10)='pmer '
blk_vname(2,10)='air_pressure_at_sea_level '
blk_vname(3,10)='Pa '
blk_vname(4,10)='?????? '
# endif
# elif defined ERA_ECMWF
! Temperature_height_above_ground
! Modif SPOUS ASAP
! blk_vname(1,1)='T2M '
blk_vname(1,1)='t2 '
! Modif SPOUS ASAP
blk_vname(2,1)='Temperature '
blk_vname(3,1)='Kelvin '
blk_vname(4,1)='?????? '
! Specific_humidity
! Modif SPOUS ASAP
! blk_vname(1,2)='Q '
blk_vname(1,2)='q2 '
! Modif SPOUS ASAP
blk_vname(2,2)='Specific Humidity at surface '
blk_vname(3,2)='Kg/Kg '
blk_vname(4,2)='?????? '
! Precipitation_rate
! Modif SPOUS ASAP
! blk_vname(1,3)='TP '
blk_vname(1,3)='precip '
! Modif SPOUS ASAP
blk_vname(2,3)='Precipitation_rate '
blk_vname(3,3)='kg/m^2/s '
blk_vname(4,3)='?????? '
! Downward_Short-Wave_Rad_Flux_surface
blk_vname(1,4)='xxx '
blk_vname(2,4)='xxx '
blk_vname(3,4)='W/m^2 '
blk_vname(4,4)='?????? '
! Upward_Short-Wave_Rad_Flux_surface
! Modif SPOUS ASAP
! blk_vname(1,5)='SSR '
blk_vname(1,5)='radsw '
! Modif SPOUS ASAP
blk_vname(2,5)='NET SHORT WAVE!!! '
blk_vname(3,5)='W/m^2 '
blk_vname(4,5)='?????? '
! Downward_Long-Wave_Rad_Flux
! Modif SPOUS ASAP
! blk_vname(1,6)='STRD '
blk_vname(1,6)='radlw '
! Modif SPOUS ASAP
blk_vname(2,6)='Downward_Long-Wave_Rad_Flux '
blk_vname(3,6)='W/m^2 '
blk_vname(4,6)='?????? '
! Upward_Long-Wave_Rad_Flux_surface
! Modif SPOUS ASAP
! blk_vname(1,7)='NOPE '
! blk_vname(2,7)='?????? '
! blk_vname(3,7)='W/m^2 '
blk_vname(1,7)='wspd '
blk_vname(2,7)='wspd '
blk_vname(3,7)='m/s '
! Modif SPOUS ASAP replace by wind speed module '
blk_vname(4,7)='?????? '
! U-component_of_wind
! Modif SPOUS ASAP
! blk_vname(1,8)='U10M '
! blk_vname(2,8)='U10M '
blk_vname(1,8)='u10 '
blk_vname(2,8)='u10 '
! Modif SPOUS ASAP '
blk_vname(3,8)='m/s '
blk_vname(4,8)='?????? '
! V-component_of_wind
! Modif SPOUS ASAP
! blk_vname(1,9)='V10M '
! blk_vname(2,9)='V10M '
blk_vname(1,9)='v10 '
blk_vname(2,9)='v10 '
! Modif SPOUS ASAP '
blk_vname(3,9)='m/s '
blk_vname(4,9)='?????? '
# else
! Temperature_height_above_ground
blk_vname(1,1)='Temperature_height_above_ground '
blk_vname(2,1)='?????? '
blk_vname(3,1)='?????? '
blk_vname(4,1)='?????? '
! Specific_humidity
blk_vname(1,2)='Specific_humidity '
blk_vname(2,2)='Specific Humidity at surface '
blk_vname(3,2)='Kg/Kg '
blk_vname(4,2)='?????? '
! Precipitation_rate
blk_vname(1,3)='Precipitation_rate '
blk_vname(2,3)='?????? '
blk_vname(3,3)='kg/m^2/s '
blk_vname(4,3)='?????? '
! Downward_Short-Wave_Rad_Flux_surface
blk_vname(1,4)='Downward_Short-Wave_Rad_Flux_surface '
blk_vname(2,4)='?????? '
blk_vname(3,4)='W/m^2 '
blk_vname(4,4)='?????? '
! Upward_Short-Wave_Rad_Flux_surface
blk_vname(1,5)='Upward_Short-Wave_Rad_Flux_surface '
blk_vname(2,5)='?????? '
blk_vname(3,5)='W/m^2 '
blk_vname(4,5)='?????? '
! Downward_Long-Wave_Rad_Flux
blk_vname(1,6)='Downward_Long-Wave_Rad_Flux '
blk_vname(2,6)='?????? '
blk_vname(3,6)='W/m^2 '
blk_vname(4,6)='?????? '
! Upward_Long-Wave_Rad_Flux_surface
blk_vname(1,7)='Upward_Long-Wave_Rad_Flux_surface '
blk_vname(2,7)='?????? '
blk_vname(3,7)='W/m^2 '
blk_vname(4,7)='?????? '
! U-component_of_wind
blk_vname(1,8)='U-component_of_wind '
blk_vname(2,8)='?????? '
blk_vname(3,8)='m/s '
blk_vname(4,8)='?????? '
! V-component_of_wind
blk_vname(1,9)='V-component_of_wind '
blk_vname(2,9)='?????? '
blk_vname(3,9)='m/s '
blk_vname(4,9)='?????? '
# endif
return
end
#endif /* JG ONLINE */
#endif /* BULK_FLUX */
! $Id: online_get_bulk.F 1458 2014-02-03 15:01:25Z gcambon $
!
!======================================================================
! CROCO is a branch of ROMS developped at IRD and INRIA, in France
! The two other branches from UCLA (Shchepetkin et al)
! and Rutgers University (Arango et al) are under MIT/X style license.
! CROCO specific routines (nesting) are under CeCILL-C license.
!
! CROCO website : http://www.croco-ocean.org
!======================================================================
!
!
! This is the "online_get_bulk.F" script
!------------------------------------------------------------------------------
! This file contains the subfunctions enabling the online extraction of the
! forcing from a NCEP/CFSR dataset. A spatial and time interpolation are applied
! to the extracted data in order to adapt these to the considered simulation
! domain as well as the associated MPI/OPENMP discretisation (if defined MPI/
! OPENMP).
!------------------------------------------------------------------------------
#include "cppdefs.h"
#if defined BULK_FLUX && defined ONLINE
!*******************************************************************************
subroutine get_bulk_online
!------------------------------------------------------------------------------
! This subfunction enables the online extraction of data from a forcing netcdf
! NCEP/CFSR dataset. It complete the extraction with a spatial interpolation and
! a recalculation of the forcing fields to generate the bulk forcing (tairg,
! rhumg, prateg, radlwg, radswg, wspdg, uwndg, vwndg) on the simulation domain.
!------------------------------------------------------------------------------
! The main steps of this extraction are:
! - Opening of the relevant NCEP/CFSR netcdf file used for the forcing of the
! considered variable.
! - Extraction from this netcdf of the data corresponding with the simulation
! domain.
! - Interpolation of this extracted dataset on the grid of the model (in serial
! as well as parallel).
! - Transformation of the various interpolated dataset into roms bulk forcings:
! tairg; rhumg; prateg; radlwg; radswg; wspdg; uwndg; vwndg.
!
! In this subroutine the aformentioned steps are completed for every bulk forcing
! bulkfilename(X) and are repeated when necessary during the time evolution of
! the simulation.
!
implicit none
# include "param.h"
# include "forces.h"
# include "scalars.h"
# include "netcdf.inc"
# include "grid.h"
# include "online.h"
integer blkvar_id, imin, imax, jmin, jmax, strt3(3), cnt3(3)
integer blk_dimlonid, blk_lonid, blk_dimlatid, blk_latid,blk_dimtimeid
integer iblk, ierr, lvar, lenstr, i, j, NX, NY, tile, subs, trd
logical firstiter
real bulkstart, bulkend
real daycfsr, timestp, gap
real(kind=4), dimension(:), allocatable :: lon0, lat0
real(kind=8), dimension(:), allocatable :: lon, lat
real(kind=8), dimension(:,:), allocatable :: var
character*16 dimname
!
! Time of the current model step
!
timestp=time+0.5*dt
!
! Initialisation
!
firstiter=.false.
!
!===== == === === ==== =========
! Loop on all the CFSR variables
!===== == === === ==== =========
!
blkvar_id = 0
10 blkvar_id = blkvar_id+1
!
! Do not process #7 : upward longwave is obsolete
!
! Modif SPOUS ASAP
! if (blkvar_id.eq.7) goto 10
! Modif SPOUS ASAP blkvar_id.eq.7 ici c'est le module du vent
# if defined ERA_ECMWF || defined AROME
!
! In the case of ERA the net short wave is used
! Net Short wave - 5 downward short wave not used
!
if (blkvar_id.eq.4) goto 10
# endif
!
! -> End of loop on blkvar_id : goto 10
!
if (blkvar_id.gt.nblkvrs) return
!
! Open a new CFSR file if necessary
!
if (newbulk(blkvar_id)) then
!
newbulk(blkvar_id)=.false.
!
! Get the file name
!
call get_bulknetcdf_names(blkvar_id)
!
! Open the file
!
lvar=lenstr(bulkfilename(blkvar_id))
if (blkvar_id .eq. 1) then
MPI_master_only write(stdout,*) 'Open Meteo file :',
& bulkfilename(blkvar_id)(1:lvar)
endif
ierr=nf_open(bulkfilename(blkvar_id)(1:lvar), nf_nowrite,
& ncidbulkO(blkvar_id))
if (ierr. ne. nf_noerr) goto 4 !--> ERROR
!
! Extract the CFSR variable index
!
lvar=lenstr(blk_vname(1, blkvar_id))
ierr=nf_inq_varid(ncidbulkO(blkvar_id),
& blk_vname(1,blkvar_id)(1:lvar),
& bulk_varid(blkvar_id))
!
! Extract the number of records
!
! ierr=nf_inq_dim(ncidbulkO(blkvar_id), bulk_tidO(blkvar_id),
! & dimname, ntbulkO(blkvar_id))
! on a une dimension record unlimited donc la commande davant retourne 0
ierr=nf_inq_dimid(ncidbulkO(blkvar_id),'time',blk_dimtimeid)
ierr=nf_inq_dimlen(ncidbulkO(blkvar_id),blk_dimtimeid,
& ntbulkO(blkvar_id))
!
! Read Longitude dimension
!
ierr=nf_inq_dimid(ncidbulkO(blkvar_id),'lon',blk_dimlonid)
if (ierr. ne. nf_noerr) goto 99 !--> ERROR
ierr=nf_inq_dimlen(ncidbulkO(blkvar_id),blk_dimlonid,
& NX0(blkvar_id))
!
! Read Latitude dimension
!
ierr=nf_inq_dimid(ncidbulkO(blkvar_id),'lat',blk_dimlatid)
if (ierr. ne. nf_noerr) goto 99 !--> ERROR
ierr=nf_inq_dimlen(ncidbulkO(blkvar_id),blk_dimlatid,
& NY0(blkvar_id))
!
!======= === =============== ======= == === ========== === =============
! Define the caracteristics, limits, of the extraction and interpolation
!======= === =============== ======= == === ========== === =============
! Read Time dimension
!
ierr=nf_inq_varid(ncidbulkO(blkvar_id),'time',
& bulk_tidO(blkvar_id))
if (ierr .ne. nf_noerr) goto 99 !--> ERROR
!
!
! First time record
!
ierr=nf_get_var1_FTYPE(ncidbulkO(blkvar_id), bulk_tidO(blkvar_id),
& 1, bulkstart)
!
! Last time record
ierr=nf_get_var1_FTYPE(ncidbulkO(blkvar_id), bulk_tidO(blkvar_id),
& ntbulkO(blkvar_id),bulkend)
!
! Length of time vector in seconds
!
bulk_cycleO(blkvar_id)=day2sec*(bulkend-bulkstart)
!
! Check if this is the first interation
!
firstiter=(itbulkO(blkvar_id).eq.0)
!
! bulk forcing parameters
!
srf_scale=1./(rho0*Cp)
# ifdef BULK_EP
stf_scale(isalt)=0.01/86400.
# endif
# if (defined BULK_SMFLUX && !defined BULK_SM_UPDATE)
sms_scale=1./rho0
# endif
!
! Leap parameter initialisation for time interpolation
!
itbulkO(blkvar_id)=2
endif
!
!======== ==== ==== === ======= ======= === ==============
! Reading data from the forcing dataset and interpolation:
!======== ==== ==== === ======= ======= === ==============
! Leap 1->2->1->2->... to keep two forcing fields for time interpolation
!
1 iblk=3-itbulkO(blkvar_id)
!
!===== = ==== ==== === === ======== ===== == =========
! Open a CFSR file for the previous month if necessary
!===== = ==== ==== === === ======== ===== == =========
!
! (i.e. when the current CFSR time limits
! are after the current model time)
!
if ((firstiter).and.(timestp.le.(bulkstart*day2sec))) then
!
! Open a new CFSR file
!
newbulk(blkvar_id)=.true.
bulk_recO(blkvar_id)=0
!
! Caracteristics (Year, month), of the CFSR file for the previous month
!
bulkmonthnum(blkvar_id)=bulkmonthnum(blkvar_id)-1
if(bulkmonthnum(blkvar_id).le.0) then
bulkyearnum(blkvar_id)=bulkyearnum(blkvar_id)-1
bulkmonthnum(blkvar_id)=12
endif
!
! Message for the opening of the CFSR file for the previous month
!
lvar=lenstr(blk_vname(1,blkvar_id))
MPI_master_only write(stdout,
& '(6x,A,1x,A,1x,I4,1x,A,1x,I2,1x,A,1x,A)') 'ONLINE_BULK --',
& 'for temporal consistency open CFSR file of year',
& bulkyearnum(blkvar_id),
& 'month', bulkmonthnum(blkvar_id), 'for',
& blk_vname(1,blkvar_id)(1:lvar)
blkvar_id=blkvar_id-1
firstiter=.false.
goto 10
endif
!
!===== ====== ========== == == ==== == ===========
! Pass NETCDF extraction if no need of extraction:
!===== ====== ========== == == ==== == ===========
! OR GO STRAIGHT to temporal interpolation if the current step is between
! already extracted time steps
!
if ((bulk_timeO(iblk,blkvar_id).le.timestp).and.
& (timestp.lt.bulk_timeO(itbulkO(blkvar_id),blkvar_id))) goto 10
!
!=========== == ====== ========
! Extraction of NETCDF records:
!=========== == ====== ========
! OR LEAP if the extration of a new time step is necessary
! Load new netcdf if new forcing
!
if (newbulk(blkvar_id)) then
blkvar_id=blkvar_id-1
goto 10
endif
!
! Record index to extract in the forcing netcdf file
!
bulk_recO(blkvar_id)=bulk_recO(blkvar_id)+1
!
!=========== == =====
! Extraction of Time:
!=========== == =====
! Time (days) associated with the record index
!
ierr=nf_get_var1_FTYPE(ncidbulkO(blkvar_id),bulk_tidO(blkvar_id),
& bulk_recO(blkvar_id),daycfsr)
if (ierr .ne. nf_noerr) goto 99
!
! Computation of the time in seconds for time interpolation
!
bulk_timeO(iblk,blkvar_id)=daycfsr*day2sec
!MPI_master_only print*,'time meteo:',
!& tool_sectodat(bulk_timeO(iblk,blkvar_id))
!
! Initialize bulk_timeO(itbulkO(blkvar_id),blkvar_id)
!
if (bulk_timeO(itbulkO(blkvar_id),blkvar_id).eq.(-1.E+20))
& bulk_timeO(itbulkO(blkvar_id),blkvar_id)=
& bulk_timeO(iblk,blkvar_id)
!
! ---------------------------------------------------------------
! Evaluation of the caracteristics of the next record to extract:
! ---------------------------------------------------------------
! When at the last record of a netcdf forcing, determination of the
! caracteristics (Year, month), of the next file to open.
!
if(bulk_recO(blkvar_id).eq.ntbulkO(blkvar_id)) then
!
! Open a new CFSR file
!
newbulk(blkvar_id)=.true.
!