Changeset 1409 for trunk/LMDZ.MARS/util/lslin.F90
- Timestamp:
- Apr 7, 2015, 11:55:58 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LMDZ.MARS/util/lslin.F90
r1073 r1409 11 11 ! from hard-coded values to a computed value) 12 12 ! Read controle field, if available TN, October 2013 13 ! Allow to chose a starting Ls and to average within Ls timestep a 14 ! (great to compare with TES and MCS data. F. Forget december 2013) 13 15 14 16 … … 23 25 character (len=50) :: title,units 24 26 ! title(),units(): [netcdf] "title" and "units" attributes 27 character (len=50) :: units_alt 28 ! var(): units of altitude which can be 'km' or 'Pa' (after zrecast) 25 29 character (len=100) :: outfile 26 30 ! outfile(): output file name … … 29 33 character (len=1) :: answer 30 34 ! answer: the character 'y' (or 'Y'), if input file is of 'concatnc' type 31 integer :: nid,varid,ierr 35 character (len=1) :: average 36 ! average: the character 'y' to average within the Ls timestep 37 integer :: nid,varid,ierr,miss 32 38 ! nid: [netcdf] ID # of input file 33 39 ! varid: [netcdf] ID # of a variable … … 36 42 ! nout: [netcdf] ID # of output file 37 43 ! varidout: [netcdf] ID # of a variable (to write in the output file) 38 integer :: i,j,k,l,x,y 44 integer :: i,j,k,l,x,y,n 39 45 ! counters for various loops 40 46 integer :: start_var … … 56 62 ! lsgcm(): time coordinate (in unevenly spaced "Ls") 57 63 ! timels(): new time coordinates (evenly spaced "Ls"; written to output file) 58 integer :: latlen,lonlen,altlen,timelen,Nls 64 integer :: latlen,lonlen,altlen,timelen,Nls,Sls 59 65 ! latlen: # of elements of lat() array 60 66 ! lonlen: # of elements of lon() array … … 91 97 real, dimension(:), allocatable :: var3dxy 92 98 ! var3dxy(): to store the temporal evolution of a variable (at fixed lat/lon/alt) 93 real :: deltatsol,deltals,resultat 99 real :: deltatsol,deltals,resultat,ls0 94 100 ! deltatsol: time step (in sols) of input file data 95 101 ! deltals: time step (in Ls) for the data sent to output 102 ! ls0: first Ls value for the data sent to output 96 103 ! resultat: to temporarily store the result of the interpolation 97 104 character (len=3) :: mon … … 99 106 real :: date 100 107 ! date: used to compute/build a fake date (for grads output) 108 real :: missing 109 ! to handle missing value when reading /writing files 110 real, dimension(2) :: valid_range 111 ! valid range 101 112 102 113 !============================================================================== … … 229 240 else 230 241 ierr=NF_INQ_DIMLEN(nid,altdim,altlen) 242 units_alt=" " 243 ierr=NF_GET_ATT_TEXT(nid,varid,"units",units_alt) 231 244 endif 232 245 write(*,*) "altlen: ",altlen … … 256 269 257 270 call initiate(outfile,lat,lon,alt,nout,& 258 latdimout,londimout,altdimout,timedimout,timevarout )271 latdimout,londimout,altdimout,timedimout,timevarout,units_alt) 259 272 260 273 !============================================================================== … … 334 347 do i=1,timelen 335 348 call sol2ls(day_ini+time(i),lsgcm(i)) 349 if (lsgcm(i).lt.lsgcm(1)) lsgcm(i)=lsgcm(i) + 360. 336 350 enddo 337 351 … … 356 370 if (0.6*deltatsol.ge.3) deltals=3. 357 371 if (0.6*deltatsol.ge.5) deltals=5. 372 ls0=lsgcm(1) ! First Ls date 358 373 else 359 374 write(*,*) "New timestep in Ls (deg)" 360 375 read(*,*) deltals 361 endif 362 NLs=int(Int((lsgcm(timelen)-lsgcm(1))/deltals) +1) 376 write(*,*) "First Ls (deg)" 377 read(*,*) ls0 378 if (ls0.lt.lsgcm(1)) then 379 write(*,*) 'with this file, the earliest Ls is ',lsgcm(1),'let s use it' 380 ls0=lsgcm(1) 381 end if 382 write(*,*) "First Ls date (deg) = ", ls0 ! FF2013 383 384 do while((average.ne.'y').and.(average.ne.'n')) 385 write(*,*) "Average data within the Ls timestep (y/n) or interpolate ? " 386 read(*,*) average 387 end do 388 endif 389 NLs=int(Int((lsgcm(timelen)-ls0)/deltals) +1) ! FF2013 363 390 !******************************************** 364 391 allocate(timels(Nls)) 365 392 366 393 ! Build timels() 367 timels(1) = 0.01*nint(100.*ls gcm(1)) ! Ehouarn: what the !!!???!!!394 timels(1) = 0.01*nint(100.*ls0) ! Ehouarn: what the !!!???!!! 368 395 do k=2,Nls 369 396 timels(k) = timels(k-1) + deltals … … 470 497 471 498 ierr = NF_GET_VAR_REAL(nid,varid,var3d) 472 473 474 !============================================================================== 475 ! 3.5 Interpolate 499 miss = NF_GET_ATT_REAL(nid,varid,"missing_value",missing) 500 miss = NF_GET_ATT_REAL(nid,varid,"valid_range",valid_range) 501 502 503 !============================================================================== 504 ! 3.6 interpolate or average 476 505 !============================================================================== 477 506 … … 483 512 ! write(*,*) 'd: x, y', x, y 484 513 do l=1,timelen 485 var3dxy(l)=var3d(x,y,l,1)514 var3dxy(l)=var3d(x,y,l,1) 486 515 enddo 487 do l=1,Nls 488 call interpolf(timels(l),resultat,lsgcm,var3dxy,timelen) 489 var3dls(x,y,l,1)=resultat 516 do n=1,Nls 517 if(average.eq.'y') then 518 resultat=0. 519 Sls=0 ! (gcm data counter within each Ls timestep) 520 do l=1,timelen 521 if((lsgcm(l).ge.(timels(n)-deltals/2.)).and. & 522 (lsgcm(l).lt.(timels(n)+deltals/2.))) then 523 if(var3dxy(l) .ne. missing) then 524 Sls= Sls +1 525 resultat = resultat + var3dxy(l) 526 end if 527 end if 528 if (Sls.ne.0) then 529 var3dls(x,y,n,1)=resultat/float(Sls) 530 else 531 var3dls(x,y,n,1)=missing 532 endif 533 enddo 534 else ! average = n 535 call interpolf(timels(n),resultat,lsgcm,var3dxy,timelen) 536 var3dls(x,y,n,1)=resultat 537 endif 490 538 enddo 491 539 enddo … … 500 548 var3dxy(l)=var3d(x,y,k,l) 501 549 enddo 502 do l=1,Nls 503 call interpolf(timels(l),resultat,lsgcm,var3dxy,timelen) 504 var3dls(x,y,k,l)=resultat 550 do n=1,Nls 551 if(average.eq.'y') then 552 resultat=0. 553 Sls=0 ! (gcm data counter within each Ls timestep) 554 do l=1,timelen 555 if((lsgcm(l).ge.(timels(n)-deltals/2.)).and. & 556 (lsgcm(l).lt.(timels(n)+deltals/2.))) then 557 if(var3dxy(l) .ne. missing) then 558 Sls= Sls +1 559 resultat = resultat + var3dxy(l) 560 end if 561 end if 562 if (Sls.ne.0) then 563 var3dls(x,y,k,n)=resultat/float(Sls) 564 else 565 var3dls(x,y,k,n)=missing 566 endif 567 enddo 568 else ! average = n 569 call interpolf(timels(n),resultat,lsgcm,var3dxy,timelen) 570 var3dls(x,y,k,n)=resultat 571 end if 505 572 enddo 506 573 enddo … … 510 577 511 578 !============================================================================== 512 ! 3. 4Write variable to output file579 ! 3.7 Write variable to output file 513 580 !============================================================================== 514 581 … … 523 590 stop "" 524 591 endif 592 593 ! In case there is a "missing value" attribute and "valid range" 594 if (miss.eq.NF_NOERR) then 595 call missing_value(nout,varidout,valid_range,missing) 596 end if 525 597 526 598 deallocate(var3d) … … 561 633 if(date.ge.305) mon='nov' 562 634 if(date.ge.335) mon='dec' 563 write(33,98) outfile635 write(33,98) "^"//outfile 564 636 98 format("DSET ",a) 565 637 write(33,99) Nls, 15,mon, int(timels(1)),nint(deltals*12),'mo' … … 571 643 !************************************ 572 644 subroutine initiate (filename,lat,lon,alt,& 573 nout,latdimout,londimout,altdimout,timedimout,timevarout )645 nout,latdimout,londimout,altdimout,timedimout,timevarout,units_alt) 574 646 !============================================================================== 575 647 ! Purpose: … … 607 679 integer, intent(out):: timevarout 608 680 ! timevarout: [netcdf] "Time" (considered as a variable) ID 681 character (len=50) :: units_alt 682 ! var(): units of altitude which can be m or Pa (after zrecast) 683 609 684 610 685 !============================================================================== … … 674 749 675 750 ierr = NF_PUT_ATT_TEXT (nout,nvarid,"long_name",8,"altitude") 676 ierr = NF_PUT_ATT_TEXT (nout,nvarid,'units',2,"km") 677 ierr = NF_PUT_ATT_TEXT (nout,nvarid,'positive',2,"up") 751 !********************* temlporaire **************** 752 !ierr = NF_PUT_ATT_TEXT (nout,nvarid,'units',2,units_alt) 753 !if((units_alt(1:2).eq.'Pa').or.(units_alt(1:2).eq.'pa')) then 754 ! ierr = NF_PUT_ATT_TEXT (nout,nvarid,'positive',2,"down") 755 !else 756 ! ierr = NF_PUT_ATT_TEXT (nout,nvarid,'positive',2,"up") 757 !end if 758 !********************* temlporaire **************** 759 ierr = NF_PUT_ATT_TEXT (nout,nvarid,'units',2,'Pa') 760 ierr = NF_PUT_ATT_TEXT (nout,nvarid,'positive',4,'down') 761 !********************* temlporaire **************** 678 762 679 763 ! End netcdf define mode … … 762 846 data year_day /669./ ! # of sols in a martian year 763 847 data peri_day /485.0/ 764 data timeperi /1.9082314/ 848 data timeperi /1.9082314/! True anomaly at vernal equinox = 2*PI-Lsperi 765 849 data e_elips /0.093358/ 766 850 data twopi /6.2831853/ ! 2.*pi … … 872 956 873 957 end 958 959 960 961 !****************************************************************************** 962 !****************************************************************************** 963 subroutine missing_value(nout,nvarid,valid_range,missing) 964 !============================================================================== 965 ! Purpose: 966 ! Write "valid_range" and "missing_value" attributes (of a given 967 ! variable) to a netcdf file 968 !============================================================================== 969 ! Remarks: 970 ! NetCDF file must be open 971 ! Variable (nvarid) ID must be set 972 !============================================================================== 973 974 implicit none 975 976 include "netcdf.inc" ! NetCDF definitions 977 978 !============================================================================== 979 ! Arguments: 980 !============================================================================== 981 integer, intent(in) :: nout 982 ! nout: [netcdf] file ID # 983 integer, intent(in) :: nvarid 984 ! varid: [netcdf] variable ID # 985 real, dimension(2), intent(in) :: valid_range 986 ! valid_range(2): [netcdf] "valid_range" attribute (min and max) 987 real, intent(in) :: missing 988 ! missing: [netcdf] "missing_value" attribute 989 990 !============================================================================== 991 ! Local variables: 992 !============================================================================== 993 integer :: ierr 994 ! ierr: [netcdf] subroutine returned error code 995 ! INTEGER nout,nvarid,ierr 996 ! REAL missing 997 ! REAL valid_range(2) 998 999 ! Switch to netcdf dataset define mode 1000 ierr = NF_REDEF (nout) 1001 if (ierr.ne.NF_NOERR) then 1002 print*,'missing_value: ' 1003 print*, NF_STRERROR(ierr) 1004 endif 1005 1006 ! Write valid_range() attribute 1007 #ifdef NC_DOUBLE 1008 ierr=NF_PUT_ATT_DOUBLE(nout,nvarid,'valid_range',NF_DOUBLE,2,valid_range) 1009 #else 1010 ierr=NF_PUT_ATT_REAL(nout,nvarid,'valid_range',NF_FLOAT,2,valid_range) 1011 #endif 1012 1013 if (ierr.ne.NF_NOERR) then 1014 print*,'missing_value: valid_range attribution failed' 1015 print*, NF_STRERROR(ierr) 1016 !write(*,*) 'NF_NOERR', NF_NOERR 1017 !CALL abort 1018 stop "" 1019 endif 1020 1021 ! Write "missing_value" attribute 1022 #ifdef NC_DOUBLE 1023 ierr= NF_PUT_ATT_DOUBLE(nout,nvarid,'missing_value',NF_DOUBLE,1,missing) 1024 #else 1025 ierr= NF_PUT_ATT_REAL(nout,nvarid,'missing_value',NF_FLOAT,1,missing) 1026 #endif 1027 1028 if (ierr.NE.NF_NOERR) then 1029 print*, 'missing_value: missing value attribution failed' 1030 print*, NF_STRERROR(ierr) 1031 ! WRITE(*,*) 'NF_NOERR', NF_NOERR 1032 ! CALL abort 1033 stop "" 1034 endif 1035 1036 ! End netcdf dataset define mode 1037 ierr = NF_ENDDEF(nout) 1038 1039 end subroutine missing_value 1040 !******************************************************************************
Note: See TracChangeset
for help on using the changeset viewer.