Changeset 1659 in lmdz_wrf


Ignore:
Timestamp:
Sep 27, 2017, 6:22:33 PM (8 years ago)
Author:
lfita
Message:

First compiling version of the code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/trajectories_overlap.f90

    r1656 r1659  
    2424
    2525! Local
    26   INTEGER                                                :: ncid, rcode
     26  INTEGER                                                :: funit, ncunit, rcode
     27  INTEGER                                                :: ierr, ios
    2728  INTEGER                                                :: Nvdims
    2829  INTEGER, DIMENSION(1)                                  :: dims1D
     
    3031  INTEGER, DIMENSION(3)                                  :: dims3D
    3132  INTEGER, DIMENSION(:), ALLOCATABLE                     :: polyN
     33  INTEGER, DIMENSION(:,:,:), ALLOCATABLE                 :: polys
    3234  REAL(r_k)                                              :: resx, resy
    3335  REAL(r_k), DIMENSION(:,:), ALLOCATABLE                 :: polyas
    34   REAL(r_k), DIMENSION(:,:,:), ALLOCATABLE               :: polys, polywctrs, finaltracks
     36  REAL(r_k), DIMENSION(:,:,:), ALLOCATABLE               :: polywctrs, finaltracks
    3537  REAL(r_k), DIMENSION(:,:,:,:), ALLOCATABLE             :: polytracks
    3638  LOGICAL                                                :: gotvar
     
    3941    Nmaxtrack
    4042
    41   NAMELIST /files/ polyfilename, poly2Dn, poluyNn, polywctrn, polywarean, varnresx, varnresy, timen
     43  NAMELIST /files/ polyfilename, poly2Dn, polyNn, polywctrn, polywarean, varnresx, varnresy, timen
    4244  NAMELIST /config/ minarea, projectn, debug
    4345
     
    6264
    6365  ! Reading namelist
    64   funit = Fileunit()
     66  funit = freeunit()
    6567  OPEN(funit, file='trajectories_overlap.namelist', status='old', form='formatted', iostat=ios)
    6668  msg = "Problems reading nameslit file: 'trajectories_overlap.namelist'"
     
    7274
    7375  ! Opening polygon file
    74   rcode = nf90_open(TRIM(filename), NF90_NOWRITE, ncid)
     76  rcode = nf90_open(TRIM(polyfilename), NF90_NOWRITE, ncunit)
    7577  IF (rcode /= NF90_NOERR) CALL handle_err(rcode)
    7678
     
    7981
    8082  ! polygons
    81   gotvar = isin_ncunit(ncid, poly2Dn)
    82   IF (.NOT.gotvar) THEN
    83     msg = "File '" // TRIM() // "' does not have 2D polygons variable '" // TRIM(poly2Dn) // "'"
    84     CALL ErrMsg(msg, fname, -1)
    85   END IF
    86   Nvdims = get_varNdims_ncunit(ncid, poly2Dn)
     83  gotvar = isin_ncunit(ncunit, poly2Dn)
     84  IF (.NOT.gotvar) THEN
     85    msg= "File '"//TRIM(polyfilename)//"' does not have 2D polygons variable '" // TRIM(poly2Dn) // "'"
     86    CALL ErrMsg(msg, fname, -1)
     87  END IF
     88  Nvdims = get_varNdims_ncunit(ncunit, poly2Dn)
    8789  IF (Nvdims /= 3) THEN
    8890    WRITE(num3S,'(I3)')Nvdims
     
    9698  msg = "Problems allocating 'polys'"
    9799  CALL ErrMsg(msg, fname, ierr)
    98   CALL get_varRK3D_ncunit(ncunit, dims3D(1), dims3D(2), dims3D(3), poly2Dn, polys)
     100  CALL get_varI3D_ncunit(ncunit, dims3D(1), dims3D(2), dims3D(3), poly2Dn, polys)
     101  IF (debug) PRINT *,"  Got variable 'polys':", UBOUND(polys)
    99102
    100103  dimx = dims3D(1)
     
    103106
    104107  ! N polygons
    105   gotvar = isin_ncunit(ncid, polyNn)
    106   IF (.NOT.gotvar) THEN
    107     msg = "File '" // TRIM() // "' does not have number of polygons variable '" // TRIM(polyNn) // "'"
    108     CALL ErrMsg(msg, fname, -1)
    109   END IF
    110   Nvdims = get_varNdims_ncunit(ncid, polyNn)
    111   IF (Nvdims /= 2) THEN
     108  gotvar = isin_ncunit(ncunit, polyNn)
     109  IF (.NOT.gotvar) THEN
     110    msg="File '"//TRIM(polyfilename)//"' does not have number of polygons variable '" // TRIM(polyNn) &
     111      // "'"
     112    CALL ErrMsg(msg, fname, -1)
     113  END IF
     114  Nvdims = get_varNdims_ncunit(ncunit, polyNn)
     115  IF (Nvdims /= 1) THEN
    112116    WRITE(num3S,'(I3)')Nvdims
    113117    msg = "Variable with N polygons '" // TRIM(polyNn) // "' has: " // num3S //                       &
    114       " it must have 2 dimensions !!"
    115     CALL ErrMsg(msg, fname, -1)
    116   END IF
    117   dims2D = get_var2dims_ncunit(ncunit, polyNn)
     118      " it must have 1 dimensions !!"
     119    CALL ErrMsg(msg, fname, -1)
     120  END IF
     121  dims1D = get_var1dims_ncunit(ncunit, polyNn)
    118122  IF (ALLOCATED(polyN)) DEALLOCATE(polyN)
    119   ALLOCATE(polyN(dims2D(1), dims2D(2)), STAT=ierr)
     123  ALLOCATE(polyN(dims1D(1)), STAT=ierr)
    120124  msg = "Problems allocating 'polyN'"
    121125  CALL ErrMsg(msg, fname, ierr)
    122   CALL get_varI2D_ncunit(ncunit, dims1D(1), dims1D(2), polyNn, polyN)
     126  CALL get_varI1D_ncunit(ncunit, dims1D(1), polyNn, polyN)
     127  IF (debug) PRINT *,"  Got variable 'polyN':", UBOUND(polyN)
    123128
    124129  ! weighted-center of the polygons
    125   gotvar = isin_ncunit(ncid, polywctrn)
    126   IF (.NOT.gotvar) THEN
    127     msg = "File '" // TRIM() // "' does not have weighted-centerd polygon variable '" //              &
     130  gotvar = isin_ncunit(ncunit, polywctrn)
     131  IF (.NOT.gotvar) THEN
     132    msg = "File '" // TRIM(polyfilename) // "' does not have weighted-centerd polygon variable '" //  &
    128133      TRIM(polywctrn) // "'"
    129134    CALL ErrMsg(msg, fname, -1)
    130135  END IF
    131   Nvdims = get_varNdims_ncunit(ncid, polywctrn)
     136  Nvdims = get_varNdims_ncunit(ncunit, polywctrn)
    132137  IF (Nvdims /= 3) THEN
    133138    WRITE(num3S,'(I3)')Nvdims
     
    141146  msg = "Problems allocating 'polywctrs'"
    142147  CALL ErrMsg(msg, fname, ierr)
    143   CALL get_varRK3D_ncunit(ncunit, dims3D(1), dims3D(2), dims3D(3), poly2Dn, polywctrs)
     148  CALL get_varRK3D_ncunit(ncunit, dims3D(1), dims3D(2), dims3D(3), polywctrn, polywctrs)
     149  IF (debug) PRINT *,"  Got variable 'polyectrs':", UBOUND(polywctrs)
    144150  Nmaxpoly = dims3D(2)
    145151  Ncoord = dims3D(3)
    146152
    147153  ! area of polygons
    148   gotvar = isin_ncunit(ncid, polywarean)
    149   IF (.NOT.gotvar) THEN
    150     msg = "File '" // TRIM() // "' does not have variable '" // TRIM(polywarean) // "'"
    151     CALL ErrMsg(msg, fname, -1)
    152   END IF
    153   Nvdims = get_varNdims_ncunit(ncid, polywarean)
    154   IF (Nvdims /= 3) THEN
     154  gotvar = isin_ncunit(ncunit, polywarean)
     155  IF (.NOT.gotvar) THEN
     156    msg = "File '" // TRIM(polyfilename) // "' does not have variable '" // TRIM(polywarean) // "'"
     157    CALL ErrMsg(msg, fname, -1)
     158  END IF
     159  Nvdims = get_varNdims_ncunit(ncunit, polywarean)
     160  IF (Nvdims /= 2) THEN
    155161    WRITE(num3S,'(I3)')Nvdims
    156162    msg = "Variable with area polygons '" // TRIM(polywarean) // "' has: " // num3S //                &
     
    163169  msg = "Problems allocating 'polyas'"
    164170  CALL ErrMsg(msg, fname, ierr)
    165   CALL get_varRK2D_ncunit(ncunit, dims2D(1), dims2D(2), poly2Dn, polyas)
     171  CALL get_varRK2D_ncunit(ncunit, dims2D(1), dims2D(2), polywarean, polyas)
     172  IF (debug) PRINT *,"  Got variable 'polyas':", UBOUND(polyas)
    166173
    167174  ! Resolution along x/y axis
    168   gotvar = isin_ncunit(ncid, varnresx)
    169   IF (.NOT.gotvar) THEN
    170     msg = "File '" // TRIM() // "' does not have variable '" // TRIM(varnresx) // "'"
    171     CALL ErrMsg(msg, fname, -1)
    172   END IF
    173   CALL get_varRK0dims_ncunit(ncunit, varnresx, resx)
    174   gotvar = isin_ncunit(ncid, varnresy)
    175   IF (.NOT.gotvar) THEN
    176     msg = "File '" // TRIM() // "' does not have variable '" // TRIM(varnresy) // "'"
    177     CALL ErrMsg(msg, fname, -1)
    178   END IF
    179   CALL get_varRK0dims_ncunit(ncunit, varnresy, resy)
    180 
    181   rcode = nf90_close(ncid)
     175  gotvar = isin_ncunit(ncunit, varnresx)
     176  IF (.NOT.gotvar) THEN
     177    msg = "File '" // TRIM(polyfilename) // "' does not have variable '" // TRIM(varnresx) // "'"
     178    CALL ErrMsg(msg, fname, -1)
     179  END IF
     180  CALL get_varRK0D_ncunit(ncunit, varnresx, resx)
     181  IF (debug) PRINT *,"  Got variable 'resx':", resx
     182
     183  gotvar = isin_ncunit(ncunit, varnresy)
     184  IF (.NOT.gotvar) THEN
     185    msg = "File '" // TRIM(polyfilename) // "' does not have variable '" // TRIM(varnresy) // "'"
     186    CALL ErrMsg(msg, fname, -1)
     187  END IF
     188  CALL get_varRK0D_ncunit(ncunit, varnresy, resy)
     189  IF (debug) PRINT *,"  Got variable 'resy':", resy
     190
     191  rcode = nf90_close(ncunit)
    182192  IF (rcode /= NF90_NOERR) CALL handle_err(rcode)
    183193
     
    205215  ! Computing trajectories
    206216  CALL poly_overlap_tracks_area(debug, dimx, dimy, dimt, minarea, polyN, polys, polywctrs, polyas,    &
    207     Nmaxpoly, Nmaxtracks, polytracks, finaltracks)
     217    Nmaxpoly, Nmaxtrack, polytracks, finaltracks)
    208218
    209219  ! Writting trajectory files
    210220
    211221  DEALLOCATE(polys)
    212   DEALLOCATE(polyNs)
     222  DEALLOCATE(polyN)
    213223  DEALLOCATE(polywctrs)
    214224  DEALLOCATE(polyas)
Note: See TracChangeset for help on using the changeset viewer.