1 | ! |
---|
2 | ! $Id $ |
---|
3 | ! |
---|
4 | SUBROUTINE nb_time_step_GCM(fichnom,timelen) |
---|
5 | |
---|
6 | use netcdf, only: nf90_open,NF90_NOWRITE,nf90_noerr,nf90_strerror, & |
---|
7 | nf90_get_var, nf90_inq_varid, nf90_inq_dimid, & |
---|
8 | nf90_inquire_dimension,nf90_close |
---|
9 | |
---|
10 | IMPLICIT NONE |
---|
11 | |
---|
12 | !======================================================================= |
---|
13 | ! |
---|
14 | ! Purpose: Read in the data_GCM_Yr*.nc the number of time step |
---|
15 | ! |
---|
16 | ! Author: RV |
---|
17 | !======================================================================= |
---|
18 | |
---|
19 | include "dimensions.h" |
---|
20 | |
---|
21 | !=============================================================================== |
---|
22 | ! Arguments: |
---|
23 | CHARACTER(LEN=*), INTENT(IN) :: fichnom !--- FILE NAME |
---|
24 | !=============================================================================== |
---|
25 | ! Local Variables |
---|
26 | CHARACTER(LEN=256) :: msg, var, modname |
---|
27 | INTEGER :: iq, fID, vID, idecal |
---|
28 | INTEGER :: ierr |
---|
29 | |
---|
30 | INTEGER :: timelen ! number of times stored in the file |
---|
31 | !----------------------------------------------------------------------- |
---|
32 | modname="nb_time_step_GCM" |
---|
33 | |
---|
34 | ! Open initial state NetCDF file |
---|
35 | var=fichnom |
---|
36 | CALL err(NF90_OPEN(var,NF90_NOWRITE,fID),"open",var) |
---|
37 | |
---|
38 | ierr = nf90_inq_varid (fID, "temps", vID) |
---|
39 | IF (ierr .NE. nf90_noerr) THEN |
---|
40 | write(*,*)"read_data_GCM: Le champ <temps> est absent" |
---|
41 | write(*,*)"read_data_GCM: J essaie <time_counter>" |
---|
42 | ierr = nf90_inq_varid (fID, "time_counter", vID) |
---|
43 | IF (ierr .NE. nf90_noerr) THEN |
---|
44 | write(*,*)"read_data_GCM: Le champ <time_counter> est absent" |
---|
45 | write(*,*)"read_data_GCM: J essaie <Time>" |
---|
46 | ierr = nf90_inq_varid (fID, "Time", vID) |
---|
47 | IF (ierr .NE. nf90_noerr) THEN |
---|
48 | write(*,*)"read_data_GCM: Le champ <Time> est absent" |
---|
49 | write(*,*)trim(nf90_strerror(ierr)) |
---|
50 | CALL ABORT_gcm("nb_time_step_GCM", "", 1) |
---|
51 | ENDIF |
---|
52 | ! Get the length of the "Time" dimension |
---|
53 | ierr = nf90_inq_dimid(fID,"Time",vID) |
---|
54 | ierr = nf90_inquire_dimension(fID,vID,len=timelen) |
---|
55 | ELSE |
---|
56 | ! Get the length of the "time_counter" dimension |
---|
57 | ierr = nf90_inq_dimid(fID,"time_counter",vID) |
---|
58 | ierr = nf90_inquire_dimension(fID,vID,len=timelen) |
---|
59 | ENDIF |
---|
60 | ELSE |
---|
61 | ! Get the length of the "temps" dimension |
---|
62 | ierr = nf90_inq_dimid(fID,"temps",vID) |
---|
63 | ierr = nf90_inquire_dimension(fID,vID,len=timelen) |
---|
64 | ENDIF |
---|
65 | |
---|
66 | CALL err(NF90_CLOSE(fID),"close",fichnom) |
---|
67 | |
---|
68 | print *, "The number of timestep of the PCM run data=", timelen |
---|
69 | |
---|
70 | CONTAINS |
---|
71 | |
---|
72 | SUBROUTINE err(ierr,typ,nam) |
---|
73 | INTEGER, INTENT(IN) :: ierr !--- NetCDF ERROR CODE |
---|
74 | CHARACTER(LEN=*), INTENT(IN) :: typ !--- TYPE OF OPERATION |
---|
75 | CHARACTER(LEN=*), INTENT(IN) :: nam !--- FIELD/FILE NAME |
---|
76 | IF(ierr==NF90_NoERR) RETURN |
---|
77 | SELECT CASE(typ) |
---|
78 | CASE('inq'); msg="Field <"//TRIM(nam)//"> is missing" |
---|
79 | CASE('get'); msg="Reading failed for <"//TRIM(nam)//">" |
---|
80 | CASE('open'); msg="File opening failed for <"//TRIM(nam)//">" |
---|
81 | CASE('close'); msg="File closing failed for <"//TRIM(nam)//">" |
---|
82 | END SELECT |
---|
83 | CALL ABORT_gcm(TRIM(modname),TRIM(msg),ierr) |
---|
84 | END SUBROUTINE err |
---|
85 | |
---|
86 | END SUBROUTINE nb_time_step_GCM |
---|