Ignore:
Timestamp:
Dec 13, 2024, 5:17:13 PM (5 weeks ago)
Author:
emillour
Message:

Generic PCM

Modify iostart routines to take netcdf index as an argument in order to
be used to read/write in other files than startfi.nc (preparing 1D
restart)

MM

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/LMDZ.GENERIC/libf/phystd/iostart.F90

    r3515 r3552  
    44PRIVATE
    55    INTEGER,SAVE :: nid_start ! NetCDF file identifier for startfi.nc file
    6     INTEGER,SAVE :: nid_restart ! NetCDF file identifier for restartfi.nc file
     6    ! INTEGER,SAVE :: nid_restart ! NetCDF file identifier for restartfi.nc file
    77!$OMP THREADPRIVATE(nid_start,nid_restart)
    88   
     
    4949CONTAINS
    5050
    51   SUBROUTINE open_startphy(filename)
     51  SUBROUTINE open_startphy(filename,nid_start)
    5252  USE netcdf, only: NF90_OPEN, NF90_NOERR, NF90_NOWRITE, nf90_strerror
    5353  USE mod_phys_lmdz_para, only: is_master, bcast
    5454  IMPLICIT NONE
    55     CHARACTER(LEN=*) :: filename
    56     INTEGER          :: ierr
     55    CHARACTER(LEN=*)      :: filename
     56    INTEGER,INTENT(INOUT) :: nid_start
     57    INTEGER               :: ierr
    5758
    5859    IF (is_master) THEN
     
    6970  END SUBROUTINE open_startphy
    7071
    71   SUBROUTINE close_startphy
     72  SUBROUTINE close_startphy(nid_start)
    7273  USE netcdf, only: NF90_CLOSE
    7374  USE mod_phys_lmdz_para, only: is_master
    7475  IMPLICIT NONE
    75     INTEGER          :: ierr
     76    INTEGER,INTENT(IN) :: nid_start
     77    INTEGER            :: ierr
    7678
    7779    IF (is_master) THEN
     
    8284
    8385
    84   FUNCTION inquire_field(Field_name)
     86  FUNCTION inquire_field(nid_start,Field_name)
    8587  ! check if a given field is present in the input file
    8688  USE netcdf, only: NF90_INQ_VARID, NF90_NOERR
    8789  USE mod_phys_lmdz_para, only: is_master, bcast
    8890  IMPLICIT NONE
     91    INTEGER,INTENT(IN)          :: nid_start
    8992    CHARACTER(LEN=*),INTENT(IN) :: Field_name
    9093    LOGICAL :: inquire_field
     
    106109
    107110
    108   FUNCTION inquire_field_ndims(Field_name)
     111  FUNCTION inquire_field_ndims(nid_start,Field_name)
    109112  ! give the number of dimensions of "Field_name" stored in the input file
    110113  USE netcdf, only: nf90_inq_varid, nf90_inquire_variable, &
     
    112115  USE mod_phys_lmdz_para, only: is_master, bcast
    113116  IMPLICIT NONE
     117    INTEGER,INTENT(IN)          :: nid_start
    114118    CHARACTER(LEN=*),INTENT(IN) :: Field_name
    115119    INTEGER :: inquire_field_ndims
     
    134138
    135139
    136   FUNCTION inquire_dimension(Field_name)
     140  FUNCTION inquire_dimension(nid_start,Field_name)
    137141  ! check if a given dimension is present in the input file
    138142  USE netcdf, only: nf90_inq_dimid, NF90_NOERR
    139143  USE mod_phys_lmdz_para, only: is_master, bcast
    140144  IMPLICIT NONE
     145    INTEGER,INTENT(IN)          :: nid_start
    141146    CHARACTER(LEN=*),INTENT(IN) :: Field_name
    142147    LOGICAL :: inquire_dimension
     
    157162  END FUNCTION inquire_dimension
    158163
    159   FUNCTION inquire_dimension_length(Field_name)
     164  FUNCTION inquire_dimension_length(nid_start,Field_name)
    160165  ! give the length of the "Field_name" dimension stored in the input file
    161166  USE netcdf, only: nf90_inquire_dimension, nf90_inq_dimid, &
     
    163168  USE mod_phys_lmdz_para, only: is_master, bcast
    164169  IMPLICIT NONE
     170    INTEGER,INTENT(IN)          :: nid_start
    165171    CHARACTER(LEN=*),INTENT(IN) :: Field_name
    166172    INTEGER :: inquire_dimension_length
     
    186192
    187193
    188   SUBROUTINE Get_Field_r1(field_name,field,found,timeindex)
     194  SUBROUTINE Get_Field_r1(nid_start,field_name,field,found,timeindex)
    189195  ! For a surface field
    190196  use mod_grid_phy_lmdz, only: klon_glo ! number of atmospheric columns (full grid)
    191197  IMPLICIT NONE
     198    INTEGER,INTENT(IN)             :: nid_start
    192199    CHARACTER(LEN=*),INTENT(IN)    :: Field_name
    193200    REAL,INTENT(INOUT)               :: Field(:)
     
    205212
    206213    IF (PRESENT(found)) THEN
    207       CALL Get_field_rgen(field_name,field,1,corners,edges,found)
     214      CALL Get_field_rgen(nid_start,field_name,field,1,corners,edges,found)
    208215    ELSE
    209       CALL Get_field_rgen(field_name,field,1,corners,edges)
     216      CALL Get_field_rgen(nid_start,field_name,field,1,corners,edges)
    210217    ENDIF
    211218     
    212219  END SUBROUTINE Get_Field_r1
    213220 
    214   SUBROUTINE Get_Field_r2(field_name,field,found,timeindex)
     221  SUBROUTINE Get_Field_r2(nid_start,field_name,field,found,timeindex)
    215222  ! For a "3D" horizontal-vertical field
    216223  use mod_grid_phy_lmdz, only: klon_glo ! number of atmospheric columns (full grid)
    217224  IMPLICIT NONE
     225    INTEGER,INTENT(IN)             :: nid_start
    218226    CHARACTER(LEN=*),INTENT(IN)    :: Field_name
    219227    REAL,INTENT(INOUT)               :: Field(:,:)
     
    232240   
    233241    IF (PRESENT(found)) THEN
    234       CALL Get_field_rgen(field_name,field,size(field,2),&
     242      CALL Get_field_rgen(nid_start,field_name,field,size(field,2),&
    235243                          corners,edges,found)
    236244    ELSE
    237       CALL Get_field_rgen(field_name,field,size(field,2),&
     245      CALL Get_field_rgen(nid_start,field_name,field,size(field,2),&
    238246                          corners,edges)
    239247    ENDIF
     
    242250  END SUBROUTINE Get_Field_r2
    243251 
    244   SUBROUTINE Get_Field_r3(field_name,field,found,timeindex)
     252  SUBROUTINE Get_Field_r3(nid_start,field_name,field,found,timeindex)
    245253  ! for a "4D" field surf/alt/??
    246254  use mod_grid_phy_lmdz, only: klon_glo ! number of atmospheric columns (full grid)
    247255  IMPLICIT NONE
     256    INTEGER,INTENT(IN)             :: nid_start
    248257    CHARACTER(LEN=*),INTENT(IN)    :: Field_name
    249258    REAL,INTENT(INOUT)               :: Field(:,:,:)
     
    263272   
    264273    IF (PRESENT(found)) THEN
    265       CALL Get_field_rgen(field_name,field,size(field,2)*size(field,3),&
     274      CALL Get_field_rgen(nid_start,field_name,field,size(field,2)*size(field,3),&
    266275                          corners,edges,found)
    267276    ELSE
    268       CALL Get_field_rgen(field_name,field,size(field,2)*size(field,3),&
     277      CALL Get_field_rgen(nid_start,field_name,field,size(field,2)*size(field,3),&
    269278                          corners,edges)
    270279    ENDIF
     
    272281  END SUBROUTINE Get_Field_r3
    273282 
    274   SUBROUTINE Get_field_rgen(field_name,field,field_size, &
     283  SUBROUTINE Get_field_rgen(nid_start,field_name,field,field_size, &
    275284                            corners,edges,found)
    276285  USE netcdf
     
    279288  USE mod_phys_lmdz_para
    280289  IMPLICIT NONE
     290    INTEGER,INTENT(IN) :: nid_start
    281291    CHARACTER(LEN=*) :: Field_name
    282292    INTEGER          :: field_size
     
    296306     
    297307      IF (ierr==NF90_NOERR) THEN
    298         CALL body(field_glo)
     308        CALL body(field_glo,nid_start)
    299309        tmp_found=.TRUE.
    300310      ELSE
     
    322332    CONTAINS
    323333     
    324      SUBROUTINE body(field_glo)
     334     SUBROUTINE body(field_glo,nid_start)
    325335       REAL :: field_glo(klon_glo*field_size)
     336       INTEGER,INTENT(IN) :: nid_start
    326337         ierr=NF90_GET_VAR(nid_start,varid,field_glo,corners,edges)
    327338         IF (ierr/=NF90_NOERR) THEN
     
    349360
    350361
    351   SUBROUTINE get_var_r0(var_name,var,found)
     362  SUBROUTINE get_var_r0(nid_start,var_name,var,found)
    352363  ! Get a scalar from input file
    353364  IMPLICIT NONE 
     365    INTEGER,INTENT(IN)           :: nid_start
    354366    CHARACTER(LEN=*),INTENT(IN)  :: var_name
    355367    REAL,INTENT(INOUT)             :: var
     
    359371   
    360372    IF (PRESENT(found)) THEN
    361       CALL Get_var_rgen(var_name,varout,size(varout),found)
     373      CALL Get_var_rgen(nid_start,var_name,varout,size(varout),found)
    362374    ELSE
    363       CALL Get_var_rgen(var_name,varout,size(varout))
     375      CALL Get_var_rgen(nid_start,var_name,varout,size(varout))
    364376    ENDIF
    365377    var=varout(1)
     
    367379  END SUBROUTINE get_var_r0
    368380
    369   SUBROUTINE get_var_r1(var_name,var,found)
     381  SUBROUTINE get_var_r1(nid_start,var_name,var,found)
    370382  ! Get a vector from input file
    371383  IMPLICIT NONE 
     
    373385    REAL,INTENT(INOUT)             :: var(:)
    374386    LOGICAL,OPTIONAL,INTENT(OUT) :: found
     387    INTEGER,INTENT(IN)           :: nid_start
    375388   
    376389    IF (PRESENT(found)) THEN
    377       CALL Get_var_rgen(var_name,var,size(var),found)
     390      CALL Get_var_rgen(nid_start,var_name,var,size(var),found)
    378391    ELSE
    379       CALL Get_var_rgen(var_name,var,size(var))
     392      CALL Get_var_rgen(nid_start,var_name,var,size(var))
    380393    ENDIF
    381394 
    382395  END SUBROUTINE get_var_r1
    383396
    384   SUBROUTINE get_var_r2(var_name,var,found)
     397  SUBROUTINE get_var_r2(nid_start,var_name,var,found)
    385398  ! Get a 2D field from input file
    386399  IMPLICIT NONE 
     
    388401    REAL,INTENT(OUT)             :: var(:,:)
    389402    LOGICAL,OPTIONAL,INTENT(OUT) :: found
     403    INTEGER,INTENT(IN)           :: nid_start
    390404   
    391405    IF (PRESENT(found)) THEN
    392       CALL Get_var_rgen(var_name,var,size(var),found)
     406      CALL Get_var_rgen(nid_start,var_name,var,size(var),found)
    393407    ELSE
    394       CALL Get_var_rgen(var_name,var,size(var))
     408      CALL Get_var_rgen(nid_start,var_name,var,size(var))
    395409    ENDIF
    396410 
    397411  END SUBROUTINE get_var_r2
    398412
    399   SUBROUTINE get_var_r3(var_name,var,found)
     413  SUBROUTINE get_var_r3(nid_start,var_name,var,found)
    400414  ! Get a 3D field frominput file
    401415  IMPLICIT NONE 
     
    403417    REAL,INTENT(INOUT)             :: var(:,:,:)
    404418    LOGICAL,OPTIONAL,INTENT(OUT) :: found
     419    INTEGER,INTENT(IN)           :: nid_start
    405420   
    406421    IF (PRESENT(found)) THEN
    407       CALL Get_var_rgen(var_name,var,size(var),found)
     422      CALL Get_var_rgen(nid_start,var_name,var,size(var),found)
    408423    ELSE
    409       CALL Get_var_rgen(var_name,var,size(var))
     424      CALL Get_var_rgen(nid_start,var_name,var,size(var))
    410425    ENDIF
    411426 
    412427  END SUBROUTINE get_var_r3
    413428
    414   SUBROUTINE Get_var_rgen(var_name,var,var_size,found)
     429  SUBROUTINE Get_var_rgen(nid_start,var_name,var,var_size,found)
    415430  USE netcdf
    416431  USE dimphy
     
    418433  USE mod_phys_lmdz_para
    419434  IMPLICIT NONE
     435    INTEGER,INTENT(IN) :: nid_start
    420436    CHARACTER(LEN=*) :: var_name
    421437    INTEGER          :: var_size
     
    463479!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    464480
    465   SUBROUTINE create_restartphy(filename)
     481  SUBROUTINE create_restartphy(filename,nid_restart)
    466482  USE netcdf, only: NF90_CREATE, NF90_CLOBBER, NF90_64BIT_OFFSET, &
    467483                    NF90_NOERR, nf90_strerror, &
     
    478494  IMPLICIT NONE
    479495    CHARACTER(LEN=*),INTENT(IN) :: filename
     496    INTEGER,INTENT(INOUT)       :: nid_restart
    480497    INTEGER                     :: ierr
    481498   
     
    580597  END SUBROUTINE create_restartphy
    581598
    582   SUBROUTINE open_restartphy(filename)
     599  SUBROUTINE open_restartphy(filename,nid_restart)
    583600  USE netcdf, only: NF90_OPEN, NF90_NOERR, NF90_WRITE, nf90_strerror
    584601  USE mod_phys_lmdz_para, only: is_master
     
    586603  IMPLICIT NONE
    587604    CHARACTER(LEN=*),INTENT(IN) :: filename
     605    INTEGER,INTENT(INOUT)       :: nid_restart
    588606    INTEGER                     :: ierr
    589607   
     
    599617  END SUBROUTINE open_restartphy
    600618
    601   SUBROUTINE close_restartphy
     619  SUBROUTINE close_restartphy(nid_restart)
    602620  USE netcdf, only: NF90_CLOSE
    603621  USE mod_phys_lmdz_para, only: is_master
    604622  IMPLICIT NONE
    605     INTEGER          :: ierr
     623    INTEGER,INTENT(IN) :: nid_restart
     624    INTEGER            :: ierr
    606625
    607626    IF (is_master) THEN
     
    611630  END SUBROUTINE close_restartphy
    612631
    613   SUBROUTINE put_field_r1(field_name,title,field,time)
     632  SUBROUTINE put_field_r1(nid_restart,field_name,title,field,time)
    614633  ! For a surface field
    615634  IMPLICIT NONE
     635  INTEGER,INTENT(IN)             :: nid_restart
    616636  CHARACTER(LEN=*),INTENT(IN)    :: field_name
    617637  CHARACTER(LEN=*),INTENT(IN)    :: title
     
    621641  IF (present(time)) THEN
    622642    ! if timeindex is present, it is a time-dependent variable
    623     CALL put_field_rgen(field_name,title,field,1,time)
     643    CALL put_field_rgen(nid_restart,field_name,title,field,1,time)
    624644  ELSE
    625     CALL put_field_rgen(field_name,title,field,1)
     645    CALL put_field_rgen(nid_restart,field_name,title,field,1)
    626646  ENDIF
    627647 
    628648  END SUBROUTINE put_field_r1
    629649
    630   SUBROUTINE put_field_r2(field_name,title,field,time)
     650  SUBROUTINE put_field_r2(nid_restart,field_name,title,field,time)
    631651  ! For a "3D" horizontal-vertical field
    632652  IMPLICIT NONE
     653  INTEGER,INTENT(IN)             :: nid_restart
    633654  CHARACTER(LEN=*),INTENT(IN)    :: field_name
    634655  CHARACTER(LEN=*),INTENT(IN)    :: title
     
    638659  IF (present(time)) THEN
    639660    ! if timeindex is present, it is a time-dependent variable
    640     CALL put_field_rgen(field_name,title,field,size(field,2),time)
     661    CALL put_field_rgen(nid_restart,field_name,title,field,size(field,2),time)
    641662  ELSE
    642     CALL put_field_rgen(field_name,title,field,size(field,2))
     663    CALL put_field_rgen(nid_restart,field_name,title,field,size(field,2))
    643664  ENDIF
    644665 
    645666  END SUBROUTINE put_field_r2
    646667
    647   SUBROUTINE put_field_r3(field_name,title,field,time)
     668  SUBROUTINE put_field_r3(nid_restart,field_name,title,field,time)
    648669  ! For a "4D" field surf/alt/??
    649670  IMPLICIT NONE
     671  INTEGER,INTENT(IN)             :: nid_restart
    650672  CHARACTER(LEN=*),INTENT(IN)    :: field_name
    651673  CHARACTER(LEN=*),INTENT(IN)    :: title
     
    655677  IF (present(time)) THEN
    656678    ! if timeindex is present, it is a time-dependent variable
    657     CALL put_field_rgen(field_name,title,field,size(field,2)*size(field,3),&
     679    CALL put_field_rgen(nid_restart,field_name,title,field,size(field,2)*size(field,3),&
    658680                        time)
    659681  ELSE 
    660     CALL put_field_rgen(field_name,title,field,size(field,2)*size(field,3))
     682    CALL put_field_rgen(nid_restart,field_name,title,field,size(field,2)*size(field,3))
    661683  ENDIF
    662684 
    663685  END SUBROUTINE put_field_r3
    664686 
    665   SUBROUTINE put_field_rgen(field_name,title,field,field_size,time)
     687  SUBROUTINE put_field_rgen(nid_restart,field_name,title,field,field_size,time)
    666688  USE netcdf
    667689  USE dimphy
     
    673695
    674696  IMPLICIT NONE
     697  INTEGER,INTENT(IN)             :: nid_restart
    675698  CHARACTER(LEN=*),INTENT(IN)    :: field_name
    676699  CHARACTER(LEN=*),INTENT(IN)    :: title
     
    918941  END SUBROUTINE put_field_rgen 
    919942 
    920   SUBROUTINE put_var_r0(var_name,title,var)
     943  SUBROUTINE put_var_r0(nid_restart,var_name,title,var)
    921944  ! Put a scalar in file
    922945   IMPLICIT NONE
     946     INTEGER,INTENT(IN)          :: nid_restart
    923947     CHARACTER(LEN=*),INTENT(IN) :: var_name
    924948     CHARACTER(LEN=*),INTENT(IN) :: title
     
    928952     varin(1)=var
    929953     
    930      CALL put_var_rgen(var_name,title,varin,size(varin))
     954     CALL put_var_rgen(nid_restart,var_name,title,varin,size(varin))
    931955
    932956  END SUBROUTINE put_var_r0
    933957
    934958
    935   SUBROUTINE put_var_r1(var_name,title,var)
     959  SUBROUTINE put_var_r1(nid_restart,var_name,title,var)
    936960  ! Put a vector in file
    937961   IMPLICIT NONE
     962     INTEGER,INTENT(IN)          :: nid_restart
    938963     CHARACTER(LEN=*),INTENT(IN) :: var_name
    939964     CHARACTER(LEN=*),INTENT(IN) :: title
    940965     REAL,INTENT(IN)             :: var(:)
    941966     
    942      CALL put_var_rgen(var_name,title,var,size(var))
     967     CALL put_var_rgen(nid_restart,var_name,title,var,size(var))
    943968
    944969  END SUBROUTINE put_var_r1
    945970 
    946   SUBROUTINE put_var_r2(var_name,title,var)
     971  SUBROUTINE put_var_r2(nid_restart,var_name,title,var)
    947972  ! Put a 2D field in file
    948973   IMPLICIT NONE
     974     INTEGER,INTENT(IN)          :: nid_restart
    949975     CHARACTER(LEN=*),INTENT(IN) :: var_name
    950976     CHARACTER(LEN=*),INTENT(IN) :: title
    951977     REAL,INTENT(IN)             :: var(:,:)
    952978     
    953      CALL put_var_rgen(var_name,title,var,size(var))
     979     CALL put_var_rgen(nid_restart,var_name,title,var,size(var))
    954980
    955981  END SUBROUTINE put_var_r2     
    956982 
    957   SUBROUTINE put_var_r3(var_name,title,var)
     983  SUBROUTINE put_var_r3(nid_restart,var_name,title,var)
    958984  ! Put a 3D field in file
    959985   IMPLICIT NONE
     986     INTEGER,INTENT(IN)          :: nid_restart
    960987     CHARACTER(LEN=*),INTENT(IN) :: var_name
    961988     CHARACTER(LEN=*),INTENT(IN) :: title
    962989     REAL,INTENT(IN)             :: var(:,:,:)
    963990     
    964      CALL put_var_rgen(var_name,title,var,size(var))
     991     CALL put_var_rgen(nid_restart,var_name,title,var,size(var))
    965992
    966993  END SUBROUTINE put_var_r3
    967994
    968   SUBROUTINE put_var_rgen(var_name,title,var,var_size)
     995  SUBROUTINE put_var_rgen(nid_restart,var_name,title,var,var_size)
    969996  USE netcdf, only: NF90_REDEF, NF90_DEF_VAR, NF90_ENDDEF, NF90_PUT_VAR, &
    970997                    NF90_FLOAT, NF90_DOUBLE, &
     
    9761003  USE ocean_slab_mod, ONLY: nslay
    9771004  IMPLICIT NONE
     1005    INTEGER,INTENT(IN)          :: nid_restart
    9781006     CHARACTER(LEN=*),INTENT(IN) :: var_name
    9791007     CHARACTER(LEN=*),INTENT(IN) :: title
     
    10591087  END SUBROUTINE put_var_rgen     
    10601088
    1061   SUBROUTINE put_var_c1(var_name,title,var)
     1089  SUBROUTINE put_var_c1(nid_restart,var_name,title,var)
    10621090  ! Put a vector of characters in file
    10631091
     
    10691097
    10701098   IMPLICIT NONE
     1099     INTEGER,INTENT(IN)          :: nid_restart
    10711100     CHARACTER(LEN=*),INTENT(IN) :: var_name
    10721101     CHARACTER(LEN=*),INTENT(IN) :: title
Note: See TracChangeset for help on using the changeset viewer.