257
258
260
261
262
263 logical, intent(out) :: rectangular
264
265 integer, intent(in) :: ng, model
266 integer, intent(in) :: Nx, Ny
267
268 real(r8), intent(out) :: Xmin, Xmax, Ymin, Ymax
269
270 real(r8), intent(out) :: X(Nx,Ny)
271 real(r8), intent(out) :: Y(Nx,Ny)
272
273 character (len=*), intent(in) :: ncname
274 character (len=*), intent(in) :: ncvname
275
276 TYPE (File_desc_t), intent(inout) :: pioFile
277 TYPE (My_VarDesc), intent(inout) :: pioVar
278
279
280
281 logical :: foundit
282
283 integer :: i, ic, j, jc
284 integer :: alen, blank1, blank2
285
286 real(r8), dimension(Nx) :: Xwrk
287 real(r8), dimension(Ny) :: Ywrk
288
289 character (len=20) :: Xname, Yname
290
291 character (len=*), parameter :: MyFile = &
292 & __FILE__//", get_varcoords_pio"
293
294 TYPE (Var_desc_t) :: my_pioVar
295
296 sourcefile=myfile
297
298
299
300
301
302
303
305 & piofile = piofile, &
306 & myvarname = ncvname)
307 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
308
309
310
311 foundit=.false.
312 rectangular=.false.
313
314 DO i=1,n_vatt
315 IF (trim(var_aname(i)).eq.'coordinates') THEN
316 alen=len_trim(var_achar(i))
317 blank1=index(var_achar(i)(1:alen),' ')
318 blank2=index(var_achar(i)(blank1+1:alen),' ')
319 xname=var_achar(i)(1:blank1-1)
320 IF (blank2.gt.0) THEN
321 yname=var_achar(i)(blank1+1:blank1+blank2-1)
322 ELSE
323 yname=var_achar(i)(blank1+1:alen)
324 END IF
325 foundit=.true.
326 EXIT
327 END IF
328 END DO
329 IF (.not.foundit) THEN
330 IF (master) WRITE (stdout,10) trim(ncvname), trim(ncname)
331 exit_flag=2
332 ioerror=0
333 END IF
334
335
336
338 & piofile = piofile, &
339 & myvarname = xname, &
340 & piovar = my_piovar)
341 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
342
343 IF (n_vdim.eq.1) THEN
345 & xname, xwrk, &
346 & piofile = piofile, &
347 & start = (/1/), &
348 & total = (/nx/))
349 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
350
351 rectangular=.true.
352 jc=0
353 DO j=1,ny
354 DO i=1,nx
355 x(i,j)=xwrk(i)
356 END DO
357 END DO
358 ELSE
360 & xname, x, &
361 & piofile = piofile, &
362 & start = (/1,1/), &
363 & total = (/nx,ny/))
364 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
365
366 jc=1
367 DO j=2,ny
368 IF (x(1,j).eq.x(1,1)) THEN
369 jc=jc+1
370 END IF
371 END DO
372 END IF
373
374
375
377 & piofile = piofile, &
378 & myvarname = yname, &
379 & piovar = my_piovar)
380 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
381
382 IF (n_vdim.eq.1) THEN
384 & yname, ywrk, &
385 & piofile = piofile, &
386 & start = (/1/), &
387 & total = (/ny/))
388 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
389
390 rectangular=.true.
391 ic=0
392 DO j=1,ny
393 DO i=1,nx
394 y(i,j)=ywrk(j)
395 END DO
396 END DO
397 ELSE
399 & yname, y, &
400 & piofile = piofile, &
401 & start = (/1,1/), &
402 & total = (/nx,ny/))
403 IF (founderror(exit_flag, noerror, __line__, myfile)) RETURN
404
405 ic=1
406 DO i=2,nx
407 IF (y(i,1).eq.y(1,1)) THEN
408 ic=ic+1
409 END IF
410 END DO
411 END IF
412
413
414
415 IF (((ic.ne.0).and.(ic.eq.nx)).and. &
416 & ((jc.ne.0).and.(jc.eq.ny))) THEN
417 rectangular=.true.
418 END IF
419
420
421
422 xmin= spval
423 xmax=-spval
424 ymin= spval
425 ymax=-spval
426 DO j=1,ny
427 DO i=1,nx
428 xmin=min(xmin,x(i,j))
429 xmax=max(xmax,x(i,j))
430 ymin=min(ymin,y(i,j))
431 ymax=max(ymax,y(i,j))
432 END DO
433 END DO
434
435 10 FORMAT (/,' GET_VARCOORDS_PIO - Cannot find "coordinates" ', &
436 & 'attribute for variable:',2x,a,/,21x,'in file:',2x,a,/, &
437 & /,21x,'This attribute is needed to interpolate input data', &
438 & /,21x,'to model grid. Following CF compliance, we need:',/, &
439 & /,21x,'float my_var(time, lat, lon) ;', &
440 & /,21x,' my_var:long_name = "my variable long name" ;', &
441 & /,21x,' my_var:units = "my variable units" ;', &
442 & /,21x,' my_var:coordinates = "lon lat" ;', &
443 & /,21x,' my_var:time = "my_var_time" ;',/)
444
445 RETURN
subroutine, public pio_netcdf_inq_var(ng, model, ncname, piofile, myvarname, searchvar, piovar, nvardim, nvaratt)