Changeset 1073 for trunk/LMDZ.MARS/util/concatnc.F90
- Timestamp:
- Oct 17, 2013, 4:19:26 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LMDZ.MARS/util/concatnc.F90
r632 r1073 18 18 ! + handle absence of ap() and bp() if aps and bps are available 19 19 ! (case of stats file) FF, November 2011 20 ! + read and write controle field, if available. TN, October 2013 20 21 ! ******************************************************** 21 22 … … 54 55 ! memolonlen: # of elements of lon(), read from the first input file 55 56 ! memoaltlen: # of elements of alt(), read from the first input file 56 real, dimension(:), allocatable:: lat,lon,alt, time57 real, dimension(:), allocatable:: lat,lon,alt,ctl,time 57 58 ! lat(): array, stores latitude coordinates 58 59 ! lon(): array, stores longitude coordinates 59 60 ! alt(): array, stores altitude coordinates 61 ! ctl(): array, stores controle coordinates 60 62 ! time(): array, stores time coordinates 61 63 integer :: nbvar,nbfile,nbvarfile,ndim … … 64 66 ! nbvarfile: total # of variables in an input file 65 67 ! ndim: [netcdf] # (3 or 4) of dimensions (for variables) 66 integer :: latdim,londim,altdim, timedim68 integer :: latdim,londim,altdim,ctldim,timedim 67 69 ! latdim: [netcdf] "latitude" dim ID 68 70 ! londim: [netcdf] "longitude" dim ID 69 71 ! altdim: [netcdf] "altdim" dim ID 72 ! ctldim: [netcdf] "ctldim" dim ID 70 73 ! timedim: [netcdf] "timedim" dim ID 71 74 integer :: gcmlayerdim ! NetCDF dimension ID for # of layers in GCM 72 integer :: latvar,lonvar,altvar, timevar75 integer :: latvar,lonvar,altvar,ctlvar,timevar 73 76 ! latvar: [netcdf] ID of "latitude" variable 74 77 ! lonvar: [netcdf] ID of "longitude" variable 75 78 ! altvar: [netcdf] ID of "altitude" variable 79 ! ctlvar: [netcdf] ID of "controle" variable 76 80 ! timevar: [netcdf] ID of "Time" variable 77 integer :: latlen,lonlen,altlen, timelen81 integer :: latlen,lonlen,altlen,ctllen,timelen 78 82 ! latlen: # of elements of lat() array 79 83 ! lonlen: # of elements of lon() array 80 ! altvar: # of elements of alt() array 84 ! altlen: # of elements of alt() array 85 ! ctllen: # of elements of ctl() array 81 86 ! timelen: # of elemnets of time() array 82 87 integer :: GCM_layers ! number of GCM atmospheric layers (may not be … … 141 146 !write(*,*) "Beginning day of the first specified file?" 142 147 write(*,*) "Starting day of the run stored in the first input file?" 148 write(*,*) " (Obsolete if the controle field is present, answer any number)" 143 149 write(*,*) "(e.g.: 100 if that run started at time=100 sols)" 144 150 read(*,*) memotime … … 320 326 ! write(*,*) "altlen: ",altlen 321 327 328 ierr=NF_INQ_DIMID(nid,"index",ctldim) 329 ierr=NF_INQ_VARID(nid,"controle",ctlvar) 330 if (ierr.NE.NF_NOERR) then 331 write(*,*) 'Field <controle> is missing in file'//file 332 ctllen=0 333 !stop "" 334 else 335 ierr=NF_INQ_DIMLEN(nid,ctldim,ctllen) 336 endif 337 ! write(*,*) "controle: ",controle 338 322 339 ! load size of aps() or sigma() (in case it is not altlen) 323 340 ! default is that GCM_layers=altlen … … 345 362 allocate(lon(lonlen)) 346 363 allocate(alt(altlen)) 364 allocate(ctl(ctllen)) 347 365 #ifdef NC_DOUBLE 348 366 ierr = NF_GET_VAR_DOUBLE(nid,latvar,lat) 349 367 ierr = NF_GET_VAR_DOUBLE(nid,lonvar,lon) 350 368 ierr = NF_GET_VAR_DOUBLE(nid,altvar,alt) 369 if (ctllen .ne. -1) ierr = NF_GET_VAR_DOUBLE(nid,ctlvar,ctl) 351 370 #else 352 371 ierr = NF_GET_VAR_REAL(nid,latvar,lat) 353 372 ierr = NF_GET_VAR_REAL(nid,lonvar,lon) 354 373 ierr = NF_GET_VAR_REAL(nid,altvar,alt) 355 #endif 374 if (ctllen .ne. -1) ierr = NF_GET_VAR_REAL(nid,ctlvar,ctl) 375 #endif 376 if (ctllen .ne. -1) then 377 if (modulo(int(memotime),669)/=modulo(int(ctl(4)),669)) then 378 write(*,'(2(A,I4),A)') "WARNING: Starting day of the run is not ",& 379 modulo(int(memotime),669)," but ",modulo(int(ctl(4)),669),"!!" 380 write(*,*) "Starting day of the run has been corrected." 381 memotime=float(modulo(int(ctl(4)),669)) 382 endif 383 endif 356 384 ! Initialize output file's lat,lon,alt and time dimensions 357 call initiate (filename,lat,lon,alt, GCM_layers,nout,&385 call initiate (filename,lat,lon,alt,ctl,GCM_layers,nout,& 358 386 latdimout,londimout,altdimout,timedimout,& 359 387 layerdimout,interlayerdimout,timevarout) … … 570 598 571 599 !****************************************************************************** 572 subroutine initiate (filename,lat,lon,alt, GCM_layers,nout,&600 subroutine initiate (filename,lat,lon,alt,ctl,GCM_layers,nout,& 573 601 latdimout,londimout,altdimout,timedimout,& 574 602 layerdimout,interlayerdimout,timevarout) … … 596 624 real, dimension(:), intent(in):: alt 597 625 ! alt(): altitude 626 real, dimension(:), intent(in):: ctl 627 ! ctl(): controle 598 628 integer,intent(in) :: GCM_layers ! number of GCM layers 599 629 integer, intent(out):: nout … … 619 649 !integer :: latdim,londim,altdim,timedim 620 650 integer :: nvarid,ierr 651 integer :: ctldimout 621 652 ! nvarid: [netcdf] ID of a variable 622 653 ! ierr: [netcdf] return error code (from called subroutines) … … 640 671 ierr = NF_DEF_DIM(nout, "longitude", size(lon), londimout) 641 672 ierr = NF_DEF_DIM(nout, "altitude", size(alt), altdimout) 673 if (size(ctl).ne.0) ierr = NF_DEF_DIM(nout, "index", size(ctl), ctldimout) 642 674 ierr = NF_DEF_DIM(nout, "Time", NF_UNLIMITED, timedimout) 643 675 ierr = NF_DEF_DIM(nout, "GCM_layers", GCM_layers, layerdimout) … … 681 713 682 714 !============================================================================== 683 ! 4. Write "altitude" (data and attributes)715 ! 5. Write "altitude" (data and attributes) 684 716 !============================================================================== 685 717 … … 704 736 #else 705 737 ierr = NF_PUT_VAR_REAL (nout,nvarid,alt) 706 #endif 738 #endif 739 740 !============================================================================== 741 ! 6. Write "controle" (data and attributes) 742 !============================================================================== 743 744 if (size(ctl).ne.0) then 745 ! Switch to netcdf define mode 746 ierr = NF_REDEF (nout) 747 748 #ifdef NC_DOUBLE 749 ierr = NF_DEF_VAR (nout,"controle",NF_DOUBLE,1,ctldimout,nvarid) 750 #else 751 ierr = NF_DEF_VAR (nout,"controle",NF_FLOAT,1,ctldimout,nvarid) 752 #endif 753 754 ierr = NF_PUT_ATT_TEXT (nout,nvarid,"title",18,"Control parameters") 755 756 ! End netcdf define mode 757 ierr = NF_ENDDEF(nout) 758 759 #ifdef NC_DOUBLE 760 ierr = NF_PUT_VAR_DOUBLE (nout,nvarid,ctl) 761 #else 762 ierr = NF_PUT_VAR_REAL (nout,nvarid,ctl) 763 #endif 764 endif 707 765 708 766 end Subroutine initiate … … 1162 1220 do i=1,timelen-1 1163 1221 if ((ls(i+1)-ls(i)) > 350) then 1164 write(*,*) "+ 360 °Ls jump solved:", ls(i), ls(i+1), "at timestep", i1222 write(*,*) "+ 360 deg Ls jump solved:", ls(i), ls(i+1), "at timestep", i 1165 1223 ls(i+1) = ls(i+1) - 360 1166 1224 write(*,*) " corrected to now be:", ls(i), ls(i+1) 1167 1225 else if ((ls(i)-ls(i+1)) > 350) then 1168 write(*,*) "- 360 °Ls jump solved:", ls(i), ls(i+1), "at timestep", i1226 write(*,*) "- 360 deg Ls jump solved:", ls(i), ls(i+1), "at timestep", i 1169 1227 ls(i+1) = ls(i+1) + 360 1170 1228 write(*,*) " corrected to now be:", ls(i), ls(i+1)
Note: See TracChangeset
for help on using the changeset viewer.