Changeset 2308 for trunk/LMDZ.MARS/util/concatnc.F90
- Timestamp:
- May 4, 2020, 11:07:20 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LMDZ.MARS/util/concatnc.F90
r2303 r2308 20 20 ! + read and write controle field, if available. TN, October 2013 21 21 ! + possibility to concatenate concat files with a coherent 22 ! time axis in the output. AB, April 2020 22 ! time axis in the output, and to redistribute the time axis 23 ! from an offset given by the user. AB, April 2020 23 24 ! ******************************************************** 24 25 … … 116 117 real :: memotime 117 118 ! memotime: (cumulative) time value, in martian days (sols) 119 real :: starttimeoffset 120 ! starttimeoffset: offset given by the user for the output time axis 121 character (len=1) :: firstsol 122 ! firstsol: =[y/n], to know whether the user offset or the first file's starting day must be used in the output 118 123 real :: missing 119 124 !PARAMETER(missing=1E+20) … … 126 131 !============================================================================== 127 132 write(*,*) 128 write(*,*) "-- Program written specifically for NetCDF 'diagfi'/'concat' files from the martian GCM --" 133 write(*,*) "-- Program written specifically for NetCDF 'diagfi'/'concat' files" 134 write(*,*) " from the martian GCM --" 129 135 write(*,*) 130 136 write(*,*) "which files do you want to use?" … … 145 151 146 152 !============================================================================== 147 ! 1.2. Ask for starting day value ( memotime)153 ! 1.2. Ask for starting day value (starttimeoffset) 148 154 !============================================================================== 149 155 150 156 write(*,*) 151 !write(*,*) "Beginning day of the first specified file?" 152 write(*,*) "Starting day of the run stored in the first input file?" 153 write(*,*) " (Obsolete if the controle field is present, answer any number)" 154 write(*,*) "(e.g.: 100 if that run started at time=100 sols)" 155 read(*,*) memotime 157 write(*,*) "Starting day to be stored in the output file time axis?" 158 write(*,*) "(e.g.: 100 if you want the output file to start at time=100 sols)" 159 read(*,*) starttimeoffset 156 160 157 161 !============================================================================== … … 174 178 !============================================================================== 175 179 180 write(*,*) 176 181 write(*,*) "Warning: to read the result with grads, choose sol" 177 182 write(*,*) "Warning: use ferret to read the non linear scale ls" … … 322 327 ! 2.2. Read (and check) dimensions of variables from input file 323 328 !============================================================================== 324 329 !============================================================================== 330 ! 2.2.1 Lat, lon, alt, GCM_layers 331 !============================================================================== 325 332 ierr=NF_INQ_DIMID(nid,"latitude",latdim) 326 333 ierr=NF_INQ_VARID(nid,"latitude",latvar) … … 349 356 ierr=NF_INQ_DIMLEN(nid,altdim,altlen) 350 357 ! write(*,*) "altlen: ",altlen 351 352 ierr=NF_INQ_DIMID(nid,"index",ctldim)353 ierr=NF_INQ_VARID(nid,"controle",ctlvar)354 if (ierr.NE.NF_NOERR) then355 write(*,*) 'Field <controle> is missing in file '//file(i)356 ctllen=0357 !stop ""358 else359 ierr=NF_INQ_DIMLEN(nid,ctldim,ctllen)360 endif361 ! write(*,*) "controle: ",controle362 358 363 359 ! load size of aps() or sigma() (in case it is not altlen) … … 375 371 376 372 !============================================================================== 373 ! 2.2.1 Check presence and read "controle" dimension & variable from input file 374 !============================================================================== 375 ierr=NF_INQ_DIMID(nid,"index",ctldim) 376 if (ierr.NE.NF_NOERR) then 377 write(*,*) 'Dimension <index> is missing in file '//file(i) 378 write(*,*) "The program continues..." 379 ctllen=0 380 !stop "" 381 else 382 ierr=NF_INQ_VARID(nid,"controle",ctlvar) 383 if (ierr.NE.NF_NOERR) then 384 write(*,*) 'Field <controle> is missing in file '//file(i) 385 write(*,*) "The program continues..." 386 ctllen=0 387 !stop "" 388 else 389 ierr=NF_INQ_DIMLEN(nid,ctldim,ctllen) 390 endif 391 endif 392 ! write(*,*) "controle: ",controle 393 394 if (ctllen .ne. 0) then ! variable controle 395 allocate(ctl(ctllen)) 396 #ifdef NC_DOUBLE 397 ierr = NF_GET_VAR_DOUBLE(nid,ctlvar,ctl) 398 #else 399 ierr = NF_GET_VAR_REAL(nid,ctlvar,ctl) 400 #endif 401 ctlsol = ctl(4) 402 endif 403 404 !============================================================================== 405 ! 2.3 Read "Time" dimension & variable from input file 406 !============================================================================== 407 ierr=NF_INQ_DIMID(nid,"Time",timedim) 408 if (ierr.NE.NF_NOERR) then 409 write(*,*) 'ERROR: Dimension <Time> is missing in file '//file(i) 410 stop "" 411 endif 412 ierr=NF_INQ_VARID(nid,"Time",timevar) 413 if (ierr.NE.NF_NOERR) then 414 write(*,*) 'ERROR: Field <Time> is missing in file '//file(i) 415 stop "" 416 endif 417 ierr=NF_INQ_DIMLEN(nid,timedim,timelen) 418 ! write(*,*) "timelen: ",timelen 419 420 ! allocate time() array and fill it with values from input file 421 allocate(time(timelen)) 422 423 #ifdef NC_DOUBLE 424 ierr = NF_GET_VAR_DOUBLE(nid,timevar,time) 425 #else 426 ierr = NF_GET_VAR_REAL(nid,timevar,time) 427 #endif 428 429 430 !============================================================================== 377 431 ! 2.3. Read (and check compatibility of) dimensions of 378 432 ! variables from input file 379 433 !============================================================================== 380 381 if (ctllen .ne. 0) then ! variable controle382 allocate(ctl(ctllen))383 #ifdef NC_DOUBLE384 ierr = NF_GET_VAR_DOUBLE(nid,ctlvar,ctl)385 #else386 ierr = NF_GET_VAR_REAL(nid,ctlvar,ctl)387 #endif388 ctlsol = ctl(4)389 endif390 434 391 435 if (i==1) then ! First call; initialize/allocate … … 406 450 ierr = NF_GET_VAR_REAL(nid,altvar,alt) 407 451 #endif 452 firstsol = 'n' ! defaut value 453 write(*,*) 408 454 if (ctllen .ne. 0) then 409 if ( modulo(int(memotime),669)/=modulo(int(ctlsol),669)) then410 write(*,*) "WARNING: Starting day of the runis not ",&411 modulo(int(memotime),669)," but ",modulo(int(ctlsol),669),"!!"412 write(*,*) " Starting day of the run has been corrected."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 output416 ctl(27) = 0. ! file controle variable (resp. day_ini and hour_ini)455 if (int(starttimeoffset) .ne. (int(ctlsol)+int(time(1))) ) then 456 write(*,*) "WARNING: Starting day of the first file is not ",& 457 int(starttimeoffset)," but ",int(ctlsol)+int(time(1)),"!" 458 write(*,*) "Answer:" 459 write(*,*) " y to use the starting day you have inputted" 460 write(*,*) " n to keep the starting day of the first file" 461 write(*,*) "as the starting day of the output file" 462 read(*,*) firstsol 417 463 endif 464 465 if (firstsol.eq.'y') then 466 write(*,*) "The day given by the user is used as the starting day of the ouput file" 467 starttimeoffset = float(int(ctlsol)+int(time(1))) + ctl(27) - starttimeoffset 468 else ! if firstsol.eq.'n' or other (default case, for retrocompatibility with previous concatnc.def) 469 write(*,*) "The starting day of the 1st file is used as the starting day of the ouput file" 470 starttimeoffset = 0 471 endif 472 473 memotime=float(int(ctlsol)+int(time(1))) + ctl(27) 474 ctl(4) = 0. ! values written in the output 475 ctl(27) = 0. ! file controle variable (resp. day_ini and hour_ini) 476 477 else ! if no variable "controle" 478 if (int(starttimeoffset) .ne. (int(time(1))) ) then 479 write(*,*) "WARNING: Starting day of the first file is not ",& 480 int(starttimeoffset)," but ",int(time(1)),"!" 481 write(*,*) "Answer:" 482 write(*,*) " y to use the starting day you have inputted" 483 write(*,*) " n to keep the starting day of the first file" 484 write(*,*) "as the starting day of the output file" 485 read(*,*) firstsol 486 endif 487 488 if (firstsol.eq.'y') then 489 write(*,*) "The day given by the user is used as the starting day of the ouput file" 490 starttimeoffset = int(time(1)) - starttimeoffset 491 else ! if firstsol.eq.'n' or other (default case, for retrocompatibility with previous concatnc.def) 492 write(*,*) "The starting day of the 1st file is used as the starting day of the ouput file" 493 starttimeoffset = 0 494 endif 495 496 memotime=float(int(time(1))) 418 497 endif 498 419 499 ! Initialize output file's lat,lon,alt and time dimensions 500 write(*,*) 420 501 call initiate (filename,lat,lon,alt,ctl,GCM_layers,nout,& 421 502 latdimout,londimout,altdimout,timedimout,& … … 429 510 ! Check that latitude,longitude and altitude of current input file 430 511 ! are identical to those of the output file 512 ! and that either all the files or no file contain the controle variable 431 513 if (memolatlen/=latlen) then 432 514 write(*,*) "ERROR: Not the same latitude axis" … … 444 526 endif ! of if (i==1) 445 527 446 !============================================================================== 447 ! 2.4. Handle "Time" dimension from input file 448 !============================================================================== 449 450 !============================================================================== 451 ! 2.4.1 Read "Time" dimension from input file 452 !============================================================================== 453 ierr=NF_INQ_DIMID(nid,"Time",timedim) 454 if (ierr.NE.NF_NOERR) then 455 write(*,*) 'ERROR: Dimension <Time> is missing in file '//file(i) 456 stop "" 457 endif 458 ierr=NF_INQ_VARID(nid,"Time",timevar) 459 if (ierr.NE.NF_NOERR) then 460 write(*,*) 'ERROR: Field <Time> is missing in file '//file(i) 461 stop "" 462 endif 463 ierr=NF_INQ_DIMLEN(nid,timedim,timelen) 464 ! write(*,*) "timelen: ",timelen 465 466 ! allocate time() array and fill it with values from input file 467 allocate(time(timelen)) 468 469 #ifdef NC_DOUBLE 470 ierr = NF_GET_VAR_DOUBLE(nid,timevar,time) 471 #else 472 ierr = NF_GET_VAR_REAL(nid,timevar,time) 473 #endif 474 475 !============================================================================== 476 ! 2.4.2 Write/extend "Time" dimension/values in output file 528 529 !============================================================================== 530 ! 2.4 Write/extend "Time" dimension/values in output file 477 531 !============================================================================== 478 532 479 533 rep=0 480 534 write(*,*) 481 write(*,'(a3,1x,f6.1)') "Sol",memotime 535 write(*,'(a3,1x,f6.1)') "Sol",memotime-starttimeoffset 482 536 ! if (ctllen.ne.0) write(*,'(a30,1x,f6.1)') "In the current file's ctl: Sol",ctlsol 483 537 … … 486 540 do k=reptime+1,reptime+timelen 487 541 rep=rep+1 488 if ((time(rep)+ctlsol).le.memotime) then542 if ((time(rep)+ctlsol).le.memotime) then 489 543 write(*,*) "ERROR : the time intervals of the files are not dissociated" 490 544 stop "" 491 545 endif 492 546 #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 547 ierr= NF_PUT_VARA_DOUBLE(nout,timevarout,k,1,ctlsol+time(rep)-starttimeoffset) 548 #else 549 ierr= NF_PUT_VARA_REAL(nout,timevarout,k,1,ctlsol+time(rep)-starttimeoffset) 550 #endif 551 ! 497 552 enddo 498 553 499 else 554 ! Compute new time offset (for further concatenations) 555 memotime=ctlsol+time(timelen) ! the actual last day of the current file 556 ! becomes the reference time for next file 557 ! leaving potential "time holes" in the output time axis 558 ! at the junction of two files' time axes 559 560 else ! if no variable "controle" 561 500 562 do k=reptime+1,reptime+timelen 501 563 rep=rep+1 502 564 #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) )565 ierr= NF_PUT_VARA_DOUBLE(nout,timevarout,k,1,memotime+time(rep)-int(time(1))-starttimeoffset) 566 #else 567 ierr= NF_PUT_VARA_REAL(nout,timevarout,k,1,memotime+time(rep)-int(time(1))-starttimeoffset) 506 568 #endif 507 569 enddo 570 571 ! Compute new time offset (for further concatenations) 572 memotime=memotime+time(timelen)-time(1) ! files are concatenated one after another 573 ! even if their time axes normally don't 574 ! directly follow each other 508 575 endif ! if ctllen.ne.0 509 510 ! Compute new time offset (for further concatenations)511 memotime=memotime+time(timelen)512 576 513 577 !============================================================================== … … 648 712 649 713 if (axis=="ls") then 714 write(*,*);write(*,*) "Converting the time axis from sol to Ls..." 650 715 call change_time_axis(nout,ierr) 651 716 endif … … 654 719 ierr=NF_CLOSE(nout) 655 720 721 write(*,*);write(*,*) "Program concatnc completed !" 656 722 contains 657 723
Note: See TracChangeset
for help on using the changeset viewer.