Advertisement
Guest User

WRF compilation Script

a guest
Nov 12th, 2014
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 25.65 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. ## Last Updated:: 30/04/2014
  4. ## It will Download and compile WRF and WPS latest version (6.0)
  5. ## Download and compile ARWpost v3.1
  6. ## For more information on ARWpost visit http://www2.mmm.ucar.edu/wrf/OnLineTutorial/Graphics/ARWpost/index.html
  7. ## Downloading the latest geographical static data (e.g. orography, topography, soil type etc.)
  8. ## for all downloading informations visit http://www2.mmm.ucar.edu/wrf/users/download/get_sources.html
  9. ## Report in: taufiq@gist.ac.kr
  10. #========================================================================================================
  11. ## IMPORTANT:: (1) For current build Choose PGI with gcc, NO_grib2 and basic nesting while options are given.
  12. ##         (2) Whole process may take 30-40min.
  13. ## Requirement:: netcdf compiled with same compiler (e.g. pgf90 with gcc)
  14. ##           Enough free space (at least 50 GB)
  15. #========================================================================================================
  16. ## Defining all environmental variables
  17. echo ${PWD}
  18. export work_dir=${PWD}
  19. export geog=$work_dir/geog
  20. export CC=/usr/bin/gcc
  21. export CPPFLAGS='-DNDEBUG -DpgiFortran'
  22. export CFLAGS='-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE'
  23. export FC=pgf90
  24. export FFLAGS='-O -w'
  25. export CXX=/usr/bin/g++
  26. export LD_LIBRARY_PATH=/usr/local/lib
  27. export NETCDF=/usr/local
  28. export WRFIO_NCD_LARGE_FILE_SUPPORT=1
  29. export WRF_EM_CORE=1
  30. ## Downloading WRF-6.0 and WPS-6.0
  31. wget www2.mmm.ucar.edu/wrf/src/WRFV3.6.TAR.gz
  32. ## WRF-3.6 updates >> http://www2.mmm.ucar.edu/wrf/users/wrfv3.6/updates-3.6.html
  33. wget www2.mmm.ucar.edu/wrf/src/WPSV3.6.TAR.gz
  34. ## WPS-3.6 updates >> http://www2.mmm.ucar.edu/wrf/users/wpsv3.6/updates-3.6.html
  35. ## Checking netcdf installation
  36. echo 'Installation went fine, if these files exists'
  37. file $NETCDF/include/netcdf.inc
  38. file $NETCDF/lib/libnetcdf.a
  39. file $NETCDF/bin/ncgen
  40. ## Installing WRF-ARW
  41. cd $work_dir
  42. gunzip WRFV3.6.TAR.gz
  43. tar -xvf WRFV3.6.TAR
  44. cd $work_dir/WRFV3
  45. echo 'Select your preferred compiler and nesting option'
  46. echo 'It is important that your WRF compiler matches the NETCDF compiler'
  47. ./configure
  48. ## Choose PGI with gcc (option 3) and basic nesting (option 1)
  49. ./compile em_real
  50. ## Check compiled WRF
  51. echo 'Installation went fine, if these files exists'
  52. file $work_dir/WRFV3/main/real.exe
  53. file $work_dir/WRFV3/main/wrf.exe
  54. file $work_dir/WRFV3/main/ndown.exe
  55. file $work_dir/WRFV3/main/nup.exe
  56. file $work_dir/WRFV3/main/tc.exe
  57. ## Compile WPS
  58. cd $work_dir
  59. gunzip WPSV3.6.TAR.gz
  60. tar -xvf WPSV3.6.TAR
  61. cd $work_dir/WPS
  62. echo 'Select your preferred compiler'
  63. ./configure
  64. ## Choose PGI with NO_GRIB2 (option 8)
  65. ./compile
  66. echo 'Installation went fine, if these files exists'
  67. file $work_dir/WPS/geogrid.exe
  68. file $work_dir/WPS/ungrib.exe
  69. file $work_dir/WPS/metgrid.exe
  70. ## Storing all geographical data (static data) required for running WPS (49 GB)
  71. ## For more information on the static data visit: http://www2.mmm.ucar.edu/wrf/users/download/get_sources_wps_geog.html
  72. cd $work_dir
  73. mkdir geog
  74. cd $geog
  75. wget www2.mmm.ucar.edu/wrf/src/wps_files/geog_complete.tar.bz2
  76. tar -xvjpf geog_complete.tar.bz2
  77. ## NOTE:: ARWpost is a post-processing software for WRF output
  78. ## It converts the WRF output into grads format
  79. ## Download and compile ARWpost
  80. wget www2.mmm.ucar.edu/wrf/src/ARWpost_V3.tar.gz
  81. gunzip ARWpost_V3.tar.gz
  82. tar -xvf ARWpost_V3.tar
  83. ## NOTE:: Certain modifications are required in the source code
  84. ## Modify the Makefile and the date module pack in src
  85. cd $work_dir/ARWpost/src
  86. ## Modify Makefile
  87. sed -i 's/-lnetcdf/& -lnetcdff/' Makefile
  88. ## Modification on date module
  89. cd $work_dir/ARWpost/src
  90. cat > module_date_pack.f90 << EOF
  91. MODULE date_pack
  92.  
  93. !  This module is able to perform three date and time functions:
  94.  
  95. !  1.  geth_idts (ndate, odate, idts)
  96. !  Get the time period between two dates.
  97.  
  98. !  2. geth_newdate ( ndate, odate, idts)
  99. !  Get the new date based on the old date and a time difference.
  100.  
  101. !  3. split_date_char ( date , century_year , month , day , hour , minute , second )
  102. !  Given the date, return the integer components.
  103.  
  104. CONTAINS
  105.  
  106. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  107.  
  108.    SUBROUTINE geth_idts (ndate, odate, idts)
  109.    
  110.       IMPLICIT NONE
  111.      
  112.       !  From 2 input mdates ('YYYY-MM-DD HH:MM:SS.ffff'),
  113.       !  compute the time difference.
  114.      
  115.       !  on entry     -  ndate  -  the new hdate.
  116.       !                  odate  -  the old hdate.
  117.      
  118.       !  on exit      -  idts    -  the change in time in seconds.
  119.      
  120.       CHARACTER (LEN=*) , INTENT(INOUT) :: ndate, odate
  121.       INTEGER           , INTENT(OUT)   :: idts
  122.      
  123.       !  Local Variables
  124.      
  125.       !  yrnew    -  indicates the year associated with "ndate"
  126.       !  yrold    -  indicates the year associated with "odate"
  127.       !  monew    -  indicates the month associated with "ndate"
  128.       !  moold    -  indicates the month associated with "odate"
  129.       !  dynew    -  indicates the day associated with "ndate"
  130.       !  dyold    -  indicates the day associated with "odate"
  131.       !  hrnew    -  indicates the hour associated with "ndate"
  132.       !  hrold    -  indicates the hour associated with "odate"
  133.       !  minew    -  indicates the minute associated with "ndate"
  134.       !  miold    -  indicates the minute associated with "odate"
  135.       !  scnew    -  indicates the second associated with "ndate"
  136.       !  scold    -  indicates the second associated with "odate"
  137.       !  i        -  loop counter
  138.       !  mday     -  a list assigning the number of days in each month
  139.      
  140.       CHARACTER (LEN=24) :: tdate
  141.       INTEGER :: olen, nlen
  142.       INTEGER :: yrnew, monew, dynew, hrnew, minew, scnew
  143.       INTEGER :: yrold, moold, dyold, hrold, miold, scold
  144.       INTEGER :: mday(12), i, newdys, olddys
  145.       LOGICAL :: npass, opass
  146.       INTEGER :: isign
  147.      
  148.       IF (odate.GT.ndate) THEN
  149.          isign = -1
  150.          tdate=ndate
  151.          ndate=odate
  152.          odate=tdate
  153.       ELSE
  154.          isign = 1
  155.       END IF
  156.      
  157.       !  Assign the number of days in a months
  158.      
  159.       mday( 1) = 31
  160.       mday( 2) = 28
  161.       mday( 3) = 31
  162.       mday( 4) = 30
  163.       mday( 5) = 31
  164.       mday( 6) = 30
  165.       mday( 7) = 31
  166.       mday( 8) = 31
  167.       mday( 9) = 30
  168.       mday(10) = 31
  169.       mday(11) = 30
  170.       mday(12) = 31
  171.      
  172.       !  Break down old hdate into parts
  173.      
  174.       hrold = 0
  175.       miold = 0
  176.       scold = 0
  177.       olen = LEN(odate)
  178.      
  179.       READ(odate(1:4),  '(I4)') yrold
  180.       READ(odate(6:7),  '(I2)') moold
  181.       READ(odate(9:10), '(I2)') dyold
  182.       IF (olen.GE.13) THEN
  183.          READ(odate(12:13),'(I2)') hrold
  184.          IF (olen.GE.16) THEN
  185.             READ(odate(15:16),'(I2)') miold
  186.             IF (olen.GE.19) THEN
  187.                READ(odate(18:19),'(I2)') scold
  188.             END IF
  189.          END IF
  190.       END IF
  191.      
  192.       !  Break down new hdate into parts
  193.      
  194.       hrnew = 0
  195.       minew = 0
  196.       scnew = 0
  197.       nlen = LEN(ndate)
  198.      
  199.       READ(ndate(1:4),  '(I4)') yrnew
  200.       READ(ndate(6:7),  '(I2)') monew
  201.       READ(ndate(9:10), '(I2)') dynew
  202.       IF (nlen.GE.13) THEN
  203.          READ(ndate(12:13),'(I2)') hrnew
  204.          IF (nlen.GE.16) THEN
  205.             READ(ndate(15:16),'(I2)') minew
  206.             IF (nlen.GE.19) THEN
  207.                READ(ndate(18:19),'(I2)') scnew
  208.             END IF
  209.          END IF
  210.       END IF
  211.      
  212.       !  Check that the dates make sense.
  213.      
  214.       npass = .true.
  215.       opass = .true.
  216.      
  217.       !  Check that the month of NDATE makes sense.
  218.      
  219.       IF ((monew.GT.12).or.(monew.LT.1)) THEN
  220.          PRINT*, 'GETH_IDTS:  Month of NDATE = ', monew
  221.          npass = .false.
  222.       END IF
  223.      
  224.       !  Check that the month of ODATE makes sense.
  225.      
  226.       IF ((moold.GT.12).or.(moold.LT.1)) THEN
  227.          PRINT*, 'GETH_IDTS:  Month of ODATE = ', moold
  228.          opass = .false.
  229.       END IF
  230.      
  231.       !  Check that the day of NDATE makes sense.
  232.      
  233.       IF (monew.ne.2) THEN
  234.       ! ...... For all months but February
  235.          IF ((dynew.GT.mday(monew)).or.(dynew.LT.1)) THEN
  236.             PRINT*, 'GETH_IDTS:  Day of NDATE = ', dynew
  237.             npass = .false.
  238.          END IF
  239.       ELSE IF (monew.eq.2) THEN
  240.       ! ...... For February
  241.          IF ((dynew.GT.nfeb(yrnew)).OR.(dynew.LT.1)) THEN
  242.             PRINT*, 'GETH_IDTS:  Day of NDATE = ', dynew
  243.             npass = .false.
  244.          END IF
  245.       END IF
  246.      
  247.       !  Check that the day of ODATE makes sense.
  248.      
  249.       IF (moold.ne.2) THEN
  250.       ! ...... For all months but February
  251.          IF ((dyold.GT.mday(moold)).or.(dyold.LT.1)) THEN
  252.             PRINT*, 'GETH_IDTS:  Day of ODATE = ', dyold
  253.             opass = .false.
  254.          END IF
  255.       ELSE IF (moold.eq.2) THEN
  256.       ! ....... For February
  257.          IF ((dyold.GT.nfeb(yrold)).or.(dyold.LT.1)) THEN
  258.             PRINT*, 'GETH_IDTS:  Day of ODATE = ', dyold
  259.             opass = .false.
  260.          END IF
  261.       END IF
  262.      
  263.       !  Check that the hour of NDATE makes sense.
  264.      
  265.       IF ((hrnew.GT.23).or.(hrnew.LT.0)) THEN
  266.          PRINT*, 'GETH_IDTS:  Hour of NDATE = ', hrnew
  267.          npass = .false.
  268.       END IF
  269.      
  270.       !  Check that the hour of ODATE makes sense.
  271.      
  272.       IF ((hrold.GT.23).or.(hrold.LT.0)) THEN
  273.          PRINT*, 'GETH_IDTS:  Hour of ODATE = ', hrold
  274.          opass = .false.
  275.       END IF
  276.      
  277.       !  Check that the minute of NDATE makes sense.
  278.      
  279.       IF ((minew.GT.59).or.(minew.LT.0)) THEN
  280.          PRINT*, 'GETH_IDTS:  Minute of NDATE = ', minew
  281.          npass = .false.
  282.       END IF
  283.      
  284.       !  Check that the minute of ODATE makes sense.
  285.      
  286.       IF ((miold.GT.59).or.(miold.LT.0)) THEN
  287.          PRINT*, 'GETH_IDTS:  Minute of ODATE = ', miold
  288.          opass = .false.
  289.       END IF
  290.      
  291.       !  Check that the second of NDATE makes sense.
  292.      
  293.       IF ((scnew.GT.59).or.(scnew.LT.0)) THEN
  294.          PRINT*, 'GETH_IDTS:  SECOND of NDATE = ', scnew
  295.          npass = .false.
  296.       END IF
  297.      
  298.       !  Check that the second of ODATE makes sense.
  299.      
  300.       IF ((scold.GT.59).or.(scold.LT.0)) THEN
  301.          PRINT*, 'GETH_IDTS:  Second of ODATE = ', scold
  302.          opass = .false.
  303.       END IF
  304.      
  305.       IF (.not. npass) THEN
  306.          PRINT*, 'Screwy NDATE: ', ndate(1:nlen)
  307.          STOP 'ndate_2'
  308.       END IF
  309.      
  310.       IF (.not. opass) THEN
  311.          PRINT*, 'Screwy ODATE: ', odate(1:olen)
  312.          STOP 'odate_1'
  313.       END IF
  314.      
  315.       !  Date Checks are completed.  Continue.
  316.      
  317.       !  Compute number of days from 1 January ODATE, 00:00:00 until ndate
  318.       !  Compute number of hours from 1 January ODATE, 00:00:00 until ndate
  319.       !  Compute number of minutes from 1 January ODATE, 00:00:00 until ndate
  320.      
  321.       newdys = 0
  322.       DO i = yrold, yrnew - 1
  323.          newdys = newdys + (365 + (nfeb(i)-28))
  324.       END DO
  325.      
  326.       IF (monew .GT. 1) THEN
  327.          mday(2) = nfeb(yrnew)
  328.          DO i = 1, monew - 1
  329.             newdys = newdys + mday(i)
  330.          END DO
  331.          mday(2) = 28
  332.       END IF
  333.      
  334.       newdys = newdys + dynew-1
  335.      
  336.       !  Compute number of hours from 1 January ODATE, 00:00:00 until odate
  337.       !  Compute number of minutes from 1 January ODATE, 00:00:00 until odate
  338.      
  339.       olddys = 0
  340.      
  341.       IF (moold .GT. 1) THEN
  342.          mday(2) = nfeb(yrold)
  343.          DO i = 1, moold - 1
  344.             olddys = olddys + mday(i)
  345.          END DO
  346.          mday(2) = 28
  347.       END IF
  348.      
  349.       olddys = olddys + dyold-1
  350.      
  351.       !  Determine the time difference in seconds
  352.      
  353.       idts = (newdys - olddys) * 86400
  354.       idts = idts + (hrnew - hrold) * 3600
  355.       idts = idts + (minew - miold) * 60
  356.       idts = idts + (scnew - scold)
  357.      
  358.       IF (isign .eq. -1) THEN
  359.          tdate=ndate
  360.          ndate=odate
  361.          odate=tdate
  362.          idts = idts * isign
  363.       END IF
  364.    
  365.    END SUBROUTINE geth_idts
  366.  
  367. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  368.  
  369.    SUBROUTINE geth_newdate (ndate, odate, idt)
  370.    
  371.       IMPLICIT NONE
  372.      
  373.       !  From old date ('YYYY-MM-DD HH:MM:SS.ffff') and
  374.       !  delta-time, compute the new date.
  375.    
  376.       !  on entry     -  odate  -  the old hdate.
  377.       !                  idt    -  the change in time
  378.    
  379.       !  on exit      -  ndate  -  the new hdate.
  380.      
  381.       INTEGER , INTENT(IN)           :: idt
  382.       CHARACTER (LEN=*) , INTENT(OUT) :: ndate
  383.       CHARACTER (LEN=*) , INTENT(IN)  :: odate
  384.      
  385.        
  386.       !  Local Variables
  387.        
  388.       !  yrold    -  indicates the year associated with "odate"
  389.       !  moold    -  indicates the month associated with "odate"
  390.       !  dyold    -  indicates the day associated with "odate"
  391.       !  hrold    -  indicates the hour associated with "odate"
  392.       !  miold    -  indicates the minute associated with "odate"
  393.       !  scold    -  indicates the second associated with "odate"
  394.        
  395.       !  yrnew    -  indicates the year associated with "ndate"
  396.       !  monew    -  indicates the month associated with "ndate"
  397.       !  dynew    -  indicates the day associated with "ndate"
  398.       !  hrnew    -  indicates the hour associated with "ndate"
  399.       !  minew    -  indicates the minute associated with "ndate"
  400.       !  scnew    -  indicates the second associated with "ndate"
  401.        
  402.       !  mday     -  a list assigning the number of days in each month
  403.      
  404.       !  i        -  loop counter
  405.       !  nday     -  the integer number of days represented by "idt"
  406.       !  nhour    -  the integer number of hours in "idt" after taking out
  407.       !              all the whole days
  408.       !  nmin     -  the integer number of minutes in "idt" after taking out
  409.       !              all the whole days and whole hours.
  410.       !  nsec     -  the integer number of minutes in "idt" after taking out
  411.       !              all the whole days, whole hours, and whole minutes.
  412.        
  413.       INTEGER :: nlen, olen
  414.       INTEGER :: yrnew, monew, dynew, hrnew, minew, scnew, frnew
  415.       INTEGER :: yrold, moold, dyold, hrold, miold, scold, frold
  416.       INTEGER :: mday(12), nday, nhour, nmin, nsec, nfrac, i, ifrc
  417.       LOGICAL :: opass
  418.       CHARACTER (LEN=10) :: hfrc
  419.       CHARACTER (LEN=1) :: sp
  420.       ! INTEGER, EXTERNAL :: nfeb  ! in the same module now
  421.  
  422.       !  Assign the number of days in a months
  423.      
  424.       mday( 1) = 31
  425.       mday( 2) = 28
  426.       mday( 3) = 31
  427.       mday( 4) = 30
  428.       mday( 5) = 31
  429.       mday( 6) = 30
  430.       mday( 7) = 31
  431.       mday( 8) = 31
  432.       mday( 9) = 30
  433.       mday(10) = 31
  434.       mday(11) = 30
  435.       mday(12) = 31
  436.      
  437.       !  Break down old hdate into parts
  438.      
  439.       hrold = 0
  440.       miold = 0
  441.       scold = 0
  442.       frold = 0
  443.       olen = LEN(odate)
  444.       IF (olen.GE.11) THEN
  445.          sp = odate(11:11)
  446.       else
  447.          sp = ' '
  448.       END IF
  449.      
  450.       !  Use internal READ statements to convert the CHARACTER string
  451.       !  date into INTEGER components.
  452.    
  453.       READ(odate(1:4),  '(I4)') yrold
  454.       READ(odate(6:7),  '(I2)') moold
  455.       READ(odate(9:10), '(I2)') dyold
  456.       IF (olen.GE.13) THEN
  457.          READ(odate(12:13),'(I2)') hrold
  458.          IF (olen.GE.16) THEN
  459.             READ(odate(15:16),'(I2)') miold
  460.             IF (olen.GE.19) THEN
  461.                READ(odate(18:19),'(I2)') scold
  462.                IF (olen.GT.20) THEN
  463.                   READ(odate(21:olen),'(I2)') frold
  464.                END IF
  465.             END IF
  466.          END IF
  467.       END IF
  468.      
  469.       !  Set the number of days in February for that year.
  470.      
  471.       mday(2) = nfeb(yrold)
  472.      
  473.       !  Check that ODATE makes sense.
  474.      
  475.       opass = .TRUE.
  476.      
  477.       !  Check that the month of ODATE makes sense.
  478.      
  479.       IF ((moold.GT.12).or.(moold.LT.1)) THEN
  480.          WRITE(*,*) 'GETH_NEWDATE:  Month of ODATE = ', moold
  481.          opass = .FALSE.
  482.       END IF
  483.      
  484.       !  Check that the day of ODATE makes sense.
  485.      
  486.       IF ((dyold.GT.mday(moold)).or.(dyold.LT.1)) THEN
  487.          WRITE(*,*) 'GETH_NEWDATE:  Day of ODATE = ', dyold
  488.          opass = .FALSE.
  489.       END IF
  490.      
  491.       !  Check that the hour of ODATE makes sense.
  492.      
  493.       IF ((hrold.GT.23).or.(hrold.LT.0)) THEN
  494.          WRITE(*,*) 'GETH_NEWDATE:  Hour of ODATE = ', hrold
  495.          opass = .FALSE.
  496.       END IF
  497.      
  498.       !  Check that the minute of ODATE makes sense.
  499.      
  500.       IF ((miold.GT.59).or.(miold.LT.0)) THEN
  501.          WRITE(*,*) 'GETH_NEWDATE:  Minute of ODATE = ', miold
  502.          opass = .FALSE.
  503.       END IF
  504.      
  505.       !  Check that the second of ODATE makes sense.
  506.      
  507.       IF ((scold.GT.59).or.(scold.LT.0)) THEN
  508.          WRITE(*,*) 'GETH_NEWDATE:  Second of ODATE = ', scold
  509.          opass = .FALSE.
  510.       END IF
  511.      
  512.       !  Check that the fractional part  of ODATE makes sense.
  513.      
  514.      
  515.       IF (.not.opass) THEN
  516.          WRITE(*,*) 'GETH_NEWDATE: Crazy ODATE: ', odate(1:olen), olen
  517.          STOP 'odate_3'
  518.       END IF
  519.      
  520.       !  Date Checks are completed.  Continue.
  521.      
  522.      
  523.       !  Compute the number of days, hours, minutes, and seconds in idt
  524.      
  525.       IF (olen.GT.20) THEN !idt should be in fractions of seconds
  526.          ifrc = olen-20
  527.          ifrc = 10**ifrc
  528.          nday   = ABS(idt)/(86400*ifrc)
  529.          nhour  = MOD(ABS(idt),86400*ifrc)/(3600*ifrc)
  530.          nmin   = MOD(ABS(idt),3600*ifrc)/(60*ifrc)
  531.          nsec   = MOD(ABS(idt),60*ifrc)/(ifrc)
  532.          nfrac = MOD(ABS(idt), ifrc)
  533.       ELSE IF (olen.eq.19) THEN  !idt should be in seconds
  534.          ifrc = 1
  535.          nday   = ABS(idt)/86400 ! Integer number of days in delta-time
  536.          nhour  = MOD(ABS(idt),86400)/3600
  537.          nmin   = MOD(ABS(idt),3600)/60
  538.          nsec   = MOD(ABS(idt),60)
  539.          nfrac  = 0
  540.       ELSE IF (olen.eq.16) THEN !idt should be in minutes
  541.          ifrc = 1
  542.          nday   = ABS(idt)/1440 ! Integer number of days in delta-time
  543.          nhour  = MOD(ABS(idt),1440)/60
  544.          nmin   = MOD(ABS(idt),60)
  545.          nsec   = 0
  546.          nfrac  = 0
  547.       ELSE IF (olen.eq.13) THEN !idt should be in hours
  548.          ifrc = 1
  549.          nday   = ABS(idt)/24 ! Integer number of days in delta-time
  550.          nhour  = MOD(ABS(idt),24)
  551.          nmin   = 0
  552.          nsec   = 0
  553.          nfrac  = 0
  554.       ELSE IF (olen.eq.10) THEN !idt should be in days
  555.          ifrc = 1
  556.          nday   = ABS(idt)/24 ! Integer number of days in delta-time
  557.          nhour  = 0
  558.          nmin   = 0
  559.          nsec   = 0
  560.          nfrac  = 0
  561.       ELSE
  562.          WRITE(*,'(''GETH_NEWDATE: Strange length for ODATE: '', i3)') &
  563.               olen
  564.          WRITE(*,*) odate(1:olen)
  565.          STOP 'odate_4'
  566.       END IF
  567.      
  568.       IF (idt.GE.0) THEN
  569.      
  570.          frnew = frold + nfrac
  571.          IF (frnew.GE.ifrc) THEN
  572.             frnew = frnew - ifrc
  573.             nsec = nsec + 1
  574.          END IF
  575.      
  576.          scnew = scold + nsec
  577.          IF (scnew .GE. 60) THEN
  578.             scnew = scnew - 60
  579.             nmin  = nmin + 1
  580.          END IF
  581.      
  582.          minew = miold + nmin
  583.          IF (minew .GE. 60) THEN
  584.             minew = minew - 60
  585.             nhour  = nhour + 1
  586.          END IF
  587.      
  588.          hrnew = hrold + nhour
  589.          IF (hrnew .GE. 24) THEN
  590.             hrnew = hrnew - 24
  591.             nday  = nday + 1
  592.          END IF
  593.      
  594.          dynew = dyold
  595.          monew = moold
  596.          yrnew = yrold
  597.          DO i = 1, nday
  598.             dynew = dynew + 1
  599.             IF (dynew.GT.mday(monew)) THEN
  600.                dynew = dynew - mday(monew)
  601.                monew = monew + 1
  602.                IF (monew .GT. 12) THEN
  603.                   monew = 1
  604.                   yrnew = yrnew + 1
  605.                   ! If the year changes, recompute the number of days in February
  606.                   mday(2) = nfeb(yrnew)
  607.                END IF
  608.             END IF
  609.          END DO
  610.      
  611.       ELSE IF (idt.LT.0) THEN
  612.      
  613.          frnew = frold - nfrac
  614.          IF (frnew .LT. 0) THEN
  615.             frnew = frnew + ifrc
  616.             nsec = nsec - 1
  617.          END IF
  618.      
  619.          scnew = scold - nsec
  620.          IF (scnew .LT. 00) THEN
  621.             scnew = scnew + 60
  622.             nmin  = nmin + 1
  623.          END IF
  624.      
  625.          minew = miold - nmin
  626.          IF (minew .LT. 00) THEN
  627.             minew = minew + 60
  628.             nhour  = nhour + 1
  629.          END IF
  630.      
  631.          hrnew = hrold - nhour
  632.          IF (hrnew .LT. 00) THEN
  633.             hrnew = hrnew + 24
  634.             nday  = nday + 1
  635.          END IF
  636.      
  637.          dynew = dyold
  638.          monew = moold
  639.          yrnew = yrold
  640.          DO i = 1, nday
  641.             dynew = dynew - 1
  642.             IF (dynew.eq.0) THEN
  643.                monew = monew - 1
  644.                IF (monew.eq.0) THEN
  645.                   monew = 12
  646.                   yrnew = yrnew - 1
  647.                   ! If the year changes, recompute the number of days in February
  648.                   mday(2) = nfeb(yrnew)
  649.                END IF
  650.                dynew = mday(monew)
  651.             END IF
  652.          END DO
  653.       END IF
  654.      
  655.       !  Now construct the new mdate
  656.      
  657.       nlen = LEN(ndate)
  658.      
  659.       IF (nlen.GT.20) THEN
  660.          WRITE(ndate(1:19),19) yrnew, monew, dynew, hrnew, minew, scnew
  661.          WRITE(hfrc,'(I10)') frnew+1000000000
  662.          ndate = ndate(1:19)//'.'//hfrc(31-nlen:10)
  663.      
  664.       ELSE IF (nlen.eq.19.or.nlen.eq.20) THEN
  665.          WRITE(ndate(1:19),19) yrnew, monew, dynew, hrnew, minew, scnew
  666.       19   format(I4.4,'-',I2.2,'-',I2.2,'_',I2.2,':',I2.2,':',I2.2)
  667.          IF (nlen.eq.20) ndate = ndate(1:19)//'.'
  668.      
  669.       ELSE IF (nlen.eq.16) THEN
  670.          WRITE(ndate,16) yrnew, monew, dynew, hrnew, minew
  671.       16   format(I4.4,'-',I2.2,'-',I2.2,'_',I2.2,':',I2.2)
  672.      
  673.       ELSE IF (nlen.eq.13) THEN
  674.          WRITE(ndate,13) yrnew, monew, dynew, hrnew
  675.       13   format(I4.4,'-',I2.2,'-',I2.2,'_',I2.2)
  676.      
  677.       ELSE IF (nlen.eq.10) THEN
  678.          WRITE(ndate,10) yrnew, monew, dynew
  679.       10   format(I4.4,'-',I2.2,'-',I2.2)
  680.      
  681.       END IF
  682.      
  683.       IF (olen.GE.11) ndate(11:11) = sp
  684.    
  685.    END SUBROUTINE geth_newdate
  686.  
  687. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  688.  
  689.    FUNCTION nfeb ( year ) RESULT (num_days)
  690.    
  691.       ! Compute the number of days in February for the given year
  692.    
  693.       IMPLICIT NONE
  694.    
  695.       INTEGER :: year
  696.       INTEGER :: num_days
  697.    
  698.       num_days = 28 ! By default, February has 28 days ...
  699.       IF (MOD(year,4).eq.0) THEN  
  700.          num_days = 29  ! But every four years, it has 29 days ...
  701.          IF (MOD(year,100).eq.0) THEN
  702.             num_days = 28  ! Except every 100 years, when it has 28 days ...
  703.             IF (MOD(year,400).eq.0) THEN
  704.                num_days = 29  ! Except every 400 years, when it has 29 days.
  705.             END IF
  706.          END IF
  707.       END IF
  708.    
  709.    END FUNCTION nfeb
  710.  
  711. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  712.    SUBROUTINE split_date_char ( date , century_year , month , day , hour , minute , second )
  713.      
  714.       IMPLICIT NONE
  715.    
  716.       !  Input data.
  717.    
  718.       CHARACTER(LEN=19) , INTENT(IN) :: date
  719.    
  720.       !  Output data.
  721.    
  722.       INTEGER , INTENT(OUT) :: century_year , month , day , hour , minute , second
  723.      
  724.       READ(date,FMT='(    I4.4)') century_year
  725.       READ(date,FMT='( 5X,I2.2)') month
  726.       READ(date,FMT='( 8X,I2.2)') day
  727.       READ(date,FMT='(11X,I2.2)') hour
  728.       READ(date,FMT='(14X,I2.2)') minute
  729.       READ(date,FMT='(17X,I2.2)') second
  730.    
  731.    END SUBROUTINE split_date_char
  732.  
  733.  
  734. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  735.    SUBROUTINE get_seconds ( date , seconds )
  736.  
  737.       IMPLICIT NONE
  738.  
  739.       !  Input data.
  740.  
  741.       CHARACTER(LEN=19) , INTENT(IN) :: date
  742.  
  743.       !  Output data.
  744.  
  745.       INTEGER               :: century_year , month , day , hour , minute , second
  746.       INTEGER , INTENT(OUT) :: seconds
  747.  
  748.       READ(date,FMT='(    I4.4)') century_year
  749.       READ(date,FMT='( 5X,I2.2)') month
  750.       READ(date,FMT='( 8X,I2.2)') day
  751.       READ(date,FMT='(11X,I2.2)') hour
  752.       READ(date,FMT='(14X,I2.2)') minute
  753.       READ(date,FMT='(17X,I2.2)') second
  754.  
  755.       seconds = second + 60*minute
  756.  
  757.    END SUBROUTINE get_seconds
  758.  
  759. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  760.    SUBROUTINE get_diff_dates ( date1 , date2  , seconds )
  761.  
  762.       IMPLICIT NONE
  763.  
  764.       !  Input data.
  765.  
  766.       CHARACTER(LEN=19) , INTENT(IN) :: date1, date2
  767.  
  768.       !  Output data.
  769.  
  770.       INTEGER               :: century_year , month , day , hour , minute , second
  771.       INTEGER               :: century_year1, month1, day1, hour1, minute1, second1
  772.       INTEGER               :: century_year2, month2, day2, hour2, minute2, second2
  773.       INTEGER , INTENT(OUT) :: seconds
  774.  
  775.       READ(date1,FMT='(    I4.4)') century_year1
  776.       READ(date1,FMT='( 5X,I2.2)') month1
  777.       READ(date1,FMT='( 8X,I2.2)') day1
  778.       READ(date1,FMT='(11X,I2.2)') hour1
  779.       READ(date1,FMT='(14X,I2.2)') minute1
  780.       READ(date1,FMT='(17X,I2.2)') second1
  781.  
  782.       READ(date2,FMT='(    I4.4)') century_year2
  783.       READ(date2,FMT='( 5X,I2.2)') month2
  784.       READ(date2,FMT='( 8X,I2.2)') day2
  785.       READ(date2,FMT='(11X,I2.2)') hour2
  786.       READ(date2,FMT='(14X,I2.2)') minute2
  787.       READ(date2,FMT='(17X,I2.2)') second2
  788.  
  789.       century_year = abs( century_year2 - century_year1 )
  790.       month        = abs( month2 - month1 )
  791.       day          = abs( day2 - day1 )
  792.       hour         = abs( hour2 - hour1 )
  793.       minute       = abs( minute2 - minute1 )
  794.       second       = abs( second2 - second1 )
  795.  
  796.       seconds = second + 60*minute + 60*60*hour + 60*60*24*day + 60*60*24*31*month + 60*60*24*365*century_year
  797.  
  798.    END SUBROUTINE get_diff_dates
  799.  
  800.    
  801. END MODULE date_pack
  802. EOF
  803. ## Configure and compile ARWpost
  804. cd $work_dir/ARWpost
  805. ./configure
  806. ./compile
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement