Changeset 2303 for trunk/LMDZ.MARS/util/concatnc.F90
- Timestamp:
- Apr 28, 2020, 11:44:08 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LMDZ.MARS/util/concatnc.F90
r2147 r2303 19 19 ! (case of stats file) FF, November 2011 20 20 ! + read and write controle field, if available. TN, October 2013 21 ! + possibility to concatenate concat files with a coherent 22 ! time axis in the output. AB, April 2020 21 23 ! ******************************************************** 22 24 … … 51 53 integer :: varid 52 54 ! varid: [netcdf] variable ID # 53 integer :: memolatlen=0,memolonlen=0,memoaltlen=0 55 integer :: memolatlen=0,memolonlen=0,memoaltlen=0,memoctllen=0 54 56 ! memolatlen: # of elements of lat(), read from the first input file 55 57 ! memolonlen: # of elements of lon(), read from the first input file 56 58 ! memoaltlen: # of elements of alt(), read from the first input file 59 ! memoctllen: # of elements of ctl(), read from the first input file 57 60 real, dimension(:), allocatable:: lat,lon,alt,ctl,time 58 61 ! lat(): array, stores latitude coordinates … … 109 112 real, dimension(:,:,:,:), allocatable :: var3d 110 113 ! var3D(,,,): 4D array to store a field 114 real :: ctlsol 115 ! ctlsol: starting sol value of the file, stored in the variable ctl() 111 116 real :: memotime 112 117 ! memotime: (cumulative) time value, in martian days (sols) … … 121 126 !============================================================================== 122 127 write(*,*) 123 write(*,*) "-- Program written specifically for NetCDF 'diagfi' files from the martian GCM --"128 write(*,*) "-- Program written specifically for NetCDF 'diagfi'/'concat' files from the martian GCM --" 124 129 write(*,*) 125 130 write(*,*) "which files do you want to use?" … … 154 159 !============================================================================== 155 160 161 write(*,*) 162 write(*,*) "opening "//trim(file(1))//"..." 156 163 ierr = NF_OPEN(file(1),NF_NOWRITE,nid) 157 164 if (ierr.NE.NF_NOERR) then … … 319 326 ierr=NF_INQ_VARID(nid,"latitude",latvar) 320 327 if (ierr.NE.NF_NOERR) then 321 write(*,*) 'ERROR: Field <latitude> is missing in file '//file(i)328 write(*,*) 'ERROR: Field <latitude> is missing in file '//file(i) 322 329 stop "" 323 330 endif … … 328 335 ierr=NF_INQ_VARID(nid,"longitude",lonvar) 329 336 if (ierr.NE.NF_NOERR) then 330 write(*,*) 'ERROR: Field <longitude> is missing in file '//file(i)337 write(*,*) 'ERROR: Field <longitude> is missing in file '//file(i) 331 338 stop "" 332 339 endif … … 337 344 ierr=NF_INQ_VARID(nid,"altitude",altvar) 338 345 if (ierr.NE.NF_NOERR) then 339 write(*,*) 'ERROR: Field <altitude> is missing in file '//file(i)346 write(*,*) 'ERROR: Field <altitude> is missing in file '//file(i) 340 347 stop "" 341 348 endif … … 346 353 ierr=NF_INQ_VARID(nid,"controle",ctlvar) 347 354 if (ierr.NE.NF_NOERR) then 348 write(*,*) 'Field <controle> is missing in file '//file355 write(*,*) 'Field <controle> is missing in file '//file(i) 349 356 ctllen=0 350 357 !stop "" … … 372 379 !============================================================================== 373 380 381 if (ctllen .ne. 0) then ! variable controle 382 allocate(ctl(ctllen)) 383 #ifdef NC_DOUBLE 384 ierr = NF_GET_VAR_DOUBLE(nid,ctlvar,ctl) 385 #else 386 ierr = NF_GET_VAR_REAL(nid,ctlvar,ctl) 387 #endif 388 ctlsol = ctl(4) 389 endif 390 374 391 if (i==1) then ! First call; initialize/allocate 375 392 memolatlen=latlen 376 393 memolonlen=lonlen 377 394 memoaltlen=altlen 395 memoctllen=ctllen 378 396 allocate(lat(latlen)) 379 397 allocate(lon(lonlen)) 380 398 allocate(alt(altlen)) 381 allocate(ctl(ctllen))382 399 #ifdef NC_DOUBLE 383 400 ierr = NF_GET_VAR_DOUBLE(nid,latvar,lat) 384 401 ierr = NF_GET_VAR_DOUBLE(nid,lonvar,lon) 385 402 ierr = NF_GET_VAR_DOUBLE(nid,altvar,alt) 386 if (ctllen .ne. -1) ierr = NF_GET_VAR_DOUBLE(nid,ctlvar,ctl)387 403 #else 388 404 ierr = NF_GET_VAR_REAL(nid,latvar,lat) 389 405 ierr = NF_GET_VAR_REAL(nid,lonvar,lon) 390 406 ierr = NF_GET_VAR_REAL(nid,altvar,alt) 391 if (ctllen .ne. -1) ierr = NF_GET_VAR_REAL(nid,ctlvar,ctl) 392 #endif 393 if (ctllen .ne. -1) then 394 if (modulo(int(memotime),669)/=modulo(int(ctl(4)),669)) then 395 write(*,'(2(A,I4),A)') "WARNING: Starting day of the run is not ",& 396 modulo(int(memotime),669)," but ",modulo(int(ctl(4)),669),"!!" 407 #endif 408 if (ctllen .ne. 0) then 409 if (modulo(int(memotime),669)/=modulo(int(ctlsol),669)) then 410 write(*,*) "WARNING: Starting day of the run is not ",& 411 modulo(int(memotime),669)," but ",modulo(int(ctlsol),669),"!!" 397 412 write(*,*) "Starting day of the run has been corrected." 398 memotime=float(modulo(int(ctl(4)),669)) + ctl(27) 399 ctl(4) = 0. 400 ctl(27) = 0. 413 ! memotime=float(modulo(int(ctl(4)),669)) + ctl(27) 414 memotime=float(int(ctlsol)) + ctl(27) 415 ctl(4) = 0. ! values written in the output 416 ctl(27) = 0. ! file controle variable (resp. day_ini and hour_ini) 401 417 endif 402 418 endif … … 416 432 write(*,*) "ERROR: Not the same latitude axis" 417 433 stop "" 418 434 else if (memolonlen/=lonlen) then 419 435 write(*,*) "ERROR: Not the same longitude axis" 420 436 stop "" 421 else if (memoaltlen/=altlen) then 422 write(*,*) "ERROR: Not the same altitude axis" 423 stop "" 437 else if (memoaltlen/=altlen) then 438 write(*,*) "ERROR: Not the same altitude axis" 439 stop "" 440 else if (memoctllen/=ctllen) then 441 write(*,*) "ERROR: Not the same controle axis" 442 stop "" 424 443 endif 425 444 endif ! of if (i==1) … … 434 453 ierr=NF_INQ_DIMID(nid,"Time",timedim) 435 454 if (ierr.NE.NF_NOERR) then 436 write(*,*) 'ERROR: Dimension <Time> is missing in file '//file(i)455 write(*,*) 'ERROR: Dimension <Time> is missing in file '//file(i) 437 456 stop "" 438 457 endif 439 458 ierr=NF_INQ_VARID(nid,"Time",timevar) 440 459 if (ierr.NE.NF_NOERR) then 441 write(*,*) 'ERROR: Field <Time> is missing in file '//file(i)460 write(*,*) 'ERROR: Field <Time> is missing in file '//file(i) 442 461 stop "" 443 462 endif … … 461 480 write(*,*) 462 481 write(*,'(a3,1x,f6.1)') "Sol",memotime 463 464 ! Add (memotime) offset and write "concatenated" time values to output file 465 do k=reptime+1,reptime+timelen 466 rep=rep+1 467 #ifdef NC_DOUBLE 468 ierr= NF_PUT_VARA_DOUBLE(nout,timevarout,k,1,memotime+time(rep)) 469 #else 470 ierr= NF_PUT_VARA_REAL(nout,timevarout,k,1,memotime+time(rep)) 471 #endif 472 enddo 482 ! if (ctllen.ne.0) write(*,'(a30,1x,f6.1)') "In the current file's ctl: Sol",ctlsol 483 484 ! Add (memotime)/(ctlsol) offset and write "concatenated" time values to output file 485 if (ctllen.ne.0) then 486 do k=reptime+1,reptime+timelen 487 rep=rep+1 488 if ((time(rep)+ctlsol).le.memotime)then 489 write(*,*) "ERROR : the time intervals of the files are not dissociated" 490 stop "" 491 endif 492 #ifdef NC_DOUBLE 493 ierr= NF_PUT_VARA_DOUBLE(nout,timevarout,k,1,ctlsol+time(rep)) 494 #else 495 ierr= NF_PUT_VARA_REAL(nout,timevarout,k,1,ctlsol+time(rep)) 496 #endif 497 enddo 498 499 else 500 do k=reptime+1,reptime+timelen 501 rep=rep+1 502 #ifdef NC_DOUBLE 503 ierr= NF_PUT_VARA_DOUBLE(nout,timevarout,k,1,memotime+time(rep)) 504 #else 505 ierr= NF_PUT_VARA_REAL(nout,timevarout,k,1,memotime+time(rep)) 506 #endif 507 enddo 508 endif ! if ctllen.ne.0 509 473 510 ! Compute new time offset (for further concatenations) 474 511 memotime=memotime+time(timelen) … … 597 634 deallocate(time) 598 635 reptime=reptime+timelen 636 637 ! Deallocate controle if needed 638 if (ctllen.ne.0) deallocate(ctl) 599 639 600 640 ! Close input file
Note: See TracChangeset
for help on using the changeset viewer.