Changeset 108 for palm/trunk/UTIL
- Timestamp:
- Aug 24, 2007 3:10:38 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
palm/trunk/UTIL/combine_plot_fields.f90
r1 r108 4 4 ! Actual revisions: 5 5 ! ----------------- 6 ! 6 ! loop for processing of output by coupled runs, id_string does not contain 7 ! modus any longer 7 8 ! 8 9 ! Former revisions: … … 59 60 ! -Mpreprocess -D__netcdf -I /home/usr5/mkanda/netcdf-3.6.1/src/f90 -r8 60 61 ! -fast -L/home/usr5/mkanda/netcdf-3.6.1/src/libsrc -lnetcdf 62 ! FIMM: 63 ! ifort combine...f90 -o combine...x 64 ! -axW -cpp -openmp -r8 -nbs -convert little_endian -D__netcdf 65 ! -I /local/netcdf/include -Vaxlib -L/local/netcdf/lib -lnetcdf 61 66 !------------------------------------------------------------------------------! 62 67 … … 69 74 ! 70 75 !-- Local variables 71 CHARACTER (LEN=2) :: modus 72 CHARACTER (LEN= 7) :: id_char76 CHARACTER (LEN=2) :: modus, model_string 77 CHARACTER (LEN=4) :: id_string 73 78 CHARACTER (LEN=10) :: dimname, var_name 74 79 CHARACTER (LEN=40) :: filename … … 79 84 80 85 INTEGER :: av, danz, i, id, & 81 j, nc_stat, nxa, nxag, nxe, nxeg, nya, &86 j, model, models, nc_stat, nxa, nxag, nxe, nxeg, nya, & 82 87 nyag, nye, nyeg, nza, nzag, nze, nzeg, pos, time_step, xa, xe, & 83 88 ya, ye, za, ze 84 89 85 INTEGER, DIMENSION(0:1) :: current_level, current_var, fanz, id_set, id_var_time, num_var 90 INTEGER, DIMENSION(0:1) :: current_level, current_var, fanz, id_set, & 91 id_var_time, num_var 86 92 87 93 INTEGER, DIMENSION(4) :: id_dims_loc … … 99 105 REAL(spk), DIMENSION(:,:,:), ALLOCATABLE :: pf3d 100 106 101 102 !103 !-- 2D-arrays for ISO2D104 !-- Main loop for the three different cross-sections, starting with xy-section105 modus = 'XY'106 107 PRINT*, '' 107 DO WHILE ( modus == 'XY' .OR. modus == 'XZ' .OR. modus == 'YZ' ) 108 ! 109 !-- Check, if file from PE0 exists. If it does not exist, PALM did not 110 !-- create any output for this cross-section. 111 danz = 0 112 WRITE (id_char,'(A2,''_'',I4.4)') modus, danz 113 INQUIRE ( FILE='PLOT2D_'//id_char, EXIST=found ) 114 ! 115 !-- Find out the number of files (equal to the number of PEs which 116 !-- have been used in PALM) and open them 117 DO WHILE ( found ) 118 119 OPEN ( danz+110, FILE='PLOT2D_'//id_char, FORM='UNFORMATTED' ) 120 danz = danz + 1 121 WRITE (id_char,'(A2,''_'',I4.4)') modus, danz 122 INQUIRE ( FILE='PLOT2D_'//id_char, EXIST=found ) 108 PRINT*, '*** combine_plot_fields ***' 109 INQUIRE( FILE='COUPLING_PORT_OPENED', EXIST=found ) 110 IF ( found ) THEN 111 models = 2 112 PRINT*, ' coupled run' 113 ELSE 114 models = 1 115 PRINT*, ' uncoupled run' 116 ENDIF 117 DO model = 1, models 118 IF ( models == 2 ) THEN 119 PRINT*, '' 120 PRINT*, '' 121 PRINT*, '*** combine_plot_fields ***' 122 IF ( model == 2 ) THEN 123 model_string = "_O" 124 PRINT*, ' now combining ocean data' 125 PRINT*, ' ========================' 126 ELSE 127 model_string = "" 128 PRINT*, ' now combining atmosphere data' 129 PRINT*, ' =============================' 130 ENDIF 131 ENDIF 132 ! 133 !-- 2D-arrays for ISO2D 134 !-- Main loop for the three different cross-sections, starting with 135 !-- xy-section 136 modus = 'XY' 137 PRINT*, '' 138 DO WHILE ( modus == 'XY' .OR. modus == 'XZ' .OR. modus == 'YZ' ) 139 ! 140 !-- Check, if file from PE0 exists. If it does not exist, PALM did not 141 !-- create any output for this cross-section. 142 danz = 0 143 WRITE (id_string,'(I4.4)') danz 144 INQUIRE ( & 145 FILE='PLOT2D_'//modus//TRIM( model_string )//'_'//id_string, & 146 EXIST=found ) 147 ! 148 !-- Find out the number of files (equal to the number of PEs which 149 !-- have been used in PALM) and open them 150 DO WHILE ( found ) 151 152 OPEN ( danz+110, & 153 FILE='PLOT2D_'//modus//TRIM( model_string )//'_'//id_string, & 154 FORM='UNFORMATTED' ) 155 danz = danz + 1 156 WRITE (id_string,'(I4.4)') danz 157 INQUIRE ( & 158 FILE='PLOT2D_'//modus//TRIM( model_string )//'_'//id_string, & 159 EXIST=found ) 160 161 ENDDO 162 163 ! 164 !-- Inquire whether an iso2d parameter file exists 165 INQUIRE( FILE='PLOT2D_'//modus//'_GLOBAL'//TRIM( model_string ), & 166 EXIST=iso2d_output ) 167 168 ! 169 !-- Inquire whether a NetCDF file exists 170 INQUIRE( FILE='DATA_2D_'//modus//'_NETCDF'//TRIM( model_string ), & 171 EXIST=netcdf_0 ) 172 173 ! 174 !-- Inquire whether a NetCDF file for time-averaged data exists 175 INQUIRE( FILE='DATA_2D_'//modus//'_AV_NETCDF'//TRIM( model_string ),& 176 EXIST=netcdf_1 ) 177 178 IF ( netcdf_0 .OR. netcdf_1 ) THEN 179 netcdf_output = .TRUE. 180 ELSE 181 netcdf_output = .FALSE. 182 ENDIF 183 184 ! 185 !-- Info-output 186 PRINT*, '' 187 PRINT*, '*** combine_plot_fields ***' 188 #if defined( __netcdf ) 189 IF ( netcdf_output ) PRINT*, ' NetCDF output enabled' 190 #else 191 IF ( netcdf_output ) THEN 192 PRINT*, '--- Sorry, no NetCDF support on this host' 193 netcdf_output = .FALSE. 194 ENDIF 195 #endif 196 IF ( danz /= 0 ) THEN 197 PRINT*, ' ',modus,'-section: ', danz, ' file(s) found' 198 ELSE 199 PRINT*, ' no ', modus, '-section data available' 200 ENDIF 201 202 IF ( netcdf_output .AND. danz /= 0 ) THEN 203 #if defined( __netcdf ) 204 DO av = 0, 1 205 206 IF ( av == 0 .AND. .NOT. netcdf_0 ) CYCLE 207 IF ( av == 1 .AND. .NOT. netcdf_1 ) CYCLE 208 209 ! 210 !-- Open NetCDF dataset 211 IF ( av == 0 ) THEN 212 filename = 'DATA_2D_'//modus//'_NETCDF' & 213 //TRIM( model_string ) 214 ELSE 215 filename = 'DATA_2D_'//modus//'_AV_NETCDF' & 216 //TRIM( model_string ) 217 ENDIF 218 nc_stat = NF90_OPEN( filename, NF90_WRITE, id_set(av) ) 219 IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 1 ) 220 221 ! 222 !-- Get the list of variables (order of variables corresponds with 223 !-- the order of data on the binary file) 224 var_list(av) = ' ' ! GET_ATT does not assign trailing blanks 225 nc_stat = NF90_GET_ATT( id_set(av), NF90_GLOBAL, 'VAR_LIST', & 226 var_list(av) ) 227 IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 2 ) 228 229 ! 230 !-- Inquire id of the time coordinate variable 231 nc_stat = NF90_INQ_VARID( id_set(av), 'time', id_var_time(av) ) 232 IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 3 ) 233 234 ! 235 !-- Count number of variables; there is one more semicolon in the 236 !-- string than variable names 237 num_var(av) = -1 238 DO i = 1, LEN( var_list(av) ) 239 IF ( var_list(av)(i:i) == ';' ) num_var(av) = num_var(av) +1 240 ENDDO 241 242 ! 243 !-- Extract the variable names from the list and inquire their 244 !-- NetCDF IDs 245 pos = INDEX( var_list(av), ';' ) 246 ! 247 !-- Loop over all variables 248 DO i = 1, num_var(av) 249 250 ! 251 !-- Extract variable name from list 252 var_list(av) = var_list(av)(pos+1:) 253 pos = INDEX( var_list(av), ';' ) 254 var_name = var_list(av)(1:pos-1) 255 256 ! 257 !-- Get variable ID from name 258 nc_stat = NF90_INQ_VARID( id_set(av), TRIM( var_name ), & 259 id_var(av,i) ) 260 IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 4 ) 261 262 ! 263 !-- Get number of x/y/z levels for that variable 264 nc_stat = NF90_INQUIRE_VARIABLE( id_set(av), id_var(av,i), & 265 dimids = id_dims_loc ) 266 IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 5 ) 267 id_dims(av,:) = id_dims_loc 268 269 ! 270 !-- Inquire dimension ID 271 DO j = 1, 4 272 nc_stat = NF90_INQUIRE_DIMENSION( id_set(av), & 273 id_dims(av,j), dimname, levels(av,i) ) 274 IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 6 ) 275 276 IF ( modus == 'XY' .AND. INDEX(dimname, 'z') /= 0 ) EXIT 277 IF ( modus == 'XZ' .AND. INDEX(dimname, 'y') /= 0 ) EXIT 278 IF ( modus == 'YZ' .AND. INDEX(dimname, 'x') /= 0 ) EXIT 279 ENDDO 280 281 ENDDO 282 283 ENDDO ! av = 0, 1 284 285 ENDIF 286 #endif 287 288 ! 289 !-- Read the arrays, as long as the end of the file is reached 290 fanz = 0 291 current_level = 1 292 current_var = 999999999 293 294 DO WHILE ( danz /= 0 ) 295 296 ! 297 !-- Loop over all files (reading data of the subdomains) 298 DO id = 0, danz-1 299 ! 300 !-- File from PE0 contains special information at the beginning, 301 !-- concerning the lower and upper indices of the total-domain used 302 !-- in PALM (nxag, nxeg, nyag, nyeg) and the lower and upper indices 303 !-- of the array to be writte by this routine (nxa, nxe, nya, 304 !-- nye). Usually in the horizontal directions nxag=-1 and nxa=0 305 !-- while all other variables have the same value (i.e. nxeg=nxe). 306 !-- Allocate necessary arrays, open the output file and write 307 !-- the coordinate informations needed by ISO2D. 308 IF ( id == 0 .AND. fanz(0) == 0 .AND. fanz(1) == 0 ) THEN 309 READ ( id+110 ) nxag, nxeg, nyag, nyeg 310 READ ( id+110 ) nxa, nxe, nya, nye 311 ALLOCATE ( eta(nya:nye), ho(nxa:nxe), hu(nxa:nxe), & 312 pf(nxag:nxeg,nyag:nyeg) ) 313 READ ( id+110 ) dx, eta, hu, ho 314 315 IF ( iso2d_output ) THEN 316 OPEN ( 2, FILE='PLOT2D_'//modus//TRIM( model_string ), & 317 FORM='UNFORMATTED' ) 318 WRITE ( 2 ) dx, eta, hu, ho 319 ENDIF 320 ENDIF 321 ! 322 !-- Read output time 323 IF ( netcdf_output .AND. id == 0 ) THEN 324 IF ( netcdf_1 ) THEN 325 READ ( id+110, END=998 ) simulated_time, time_step, av 326 ELSE 327 ! 328 !-- For compatibility with earlier PALM versions 329 READ ( id+110, END=998 ) simulated_time, time_step 330 av = 0 331 ENDIF 332 ENDIF 333 ! 334 !-- Read subdomain indices 335 READ ( id+110, END=998 ) xa, xe, ya, ye 336 ! 337 !-- IF the PE made no output (in case that no part of the 338 !-- cross-section is situated on this PE), indices have the 339 !-- value -1 340 IF ( .NOT. ( xa == -1 .AND. xe == -1 .AND. & 341 ya == -1 .AND. ye == -1 ) ) THEN 342 ! 343 !-- Read the subdomain grid-point values 344 READ ( id+110 ) pf(xa:xe,ya:ye) 345 ENDIF 346 IF ( id == 0 ) fanz(av) = fanz(av) + 1 347 348 ENDDO 349 ! 350 !-- Write the data of the total domain cross-section 351 IF ( iso2d_output ) WRITE ( 2 ) pf(nxa:nxe,nya:nye) 352 353 ! 354 !-- Write same data in NetCDF format 355 IF ( netcdf_output ) THEN 356 #if defined( __netcdf ) 357 ! 358 !-- Check if a new time step has begun; if yes write data to time 359 !-- axis 360 IF ( current_var(av) > num_var(av) ) THEN 361 current_var(av) = 1 362 nc_stat = NF90_PUT_VAR( id_set(av), id_var_time(av), & 363 (/ simulated_time /), & 364 start = (/ time_step /), & 365 count = (/ 1 /) ) 366 IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 7 ) 367 ENDIF 368 369 ! 370 !-- Now write the data; this is mode dependent 371 SELECT CASE ( modus ) 372 373 CASE ( 'XY' ) 374 nc_stat = NF90_PUT_VAR( id_set(av), & 375 id_var(av,current_var(av)), & 376 pf(nxa:nxe,nya:nye), & 377 start = (/ 1, 1, current_level(av), time_step /), & 378 count = (/ nxe-nxa+1, nye-nya+1, 1, 1 /) ) 379 IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 8) 380 381 CASE ( 'XZ' ) 382 nc_stat = NF90_PUT_VAR( id_set(av), & 383 id_var(av,current_var(av)), & 384 pf(nxa:nxe,nya:nye), & 385 start = (/ 1, current_level(av), 1, time_step /), & 386 count = (/ nxe-nxa+1, 1, nye-nya+1, 1 /) ) 387 IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 9) 388 389 CASE ( 'YZ' ) 390 nc_stat = NF90_PUT_VAR( id_set(av), & 391 id_var(av,current_var(av)), & 392 pf(nxa:nxe,nya:nye), & 393 start = (/ current_level(av), 1, 1, time_step /), & 394 count = (/ 1, nxe-nxa+1, nye-nya+1, 1 /) ) 395 IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error(10) 396 397 END SELECT 398 399 ! 400 !-- Data is written, check if max level is reached 401 current_level(av) = current_level(av) + 1 402 IF ( current_level(av) > levels(av,current_var(av)) ) THEN 403 current_level(av) = 1 404 current_var(av) = current_var(av) + 1 405 ENDIF 406 407 ENDIF 408 #endif 409 410 ENDDO 411 412 998 IF ( danz /= 0 ) THEN 413 ! 414 !-- Print the number of the arrays processed 415 WRITE (*,'(16X,I4,A)') fanz(0)+fanz(1), ' array(s) processed' 416 IF ( fanz(1) /= 0 ) THEN 417 WRITE (*,'(16X,I4,A)') fanz(1), ' array(s) are time-averaged' 418 ENDIF 419 420 ! 421 !-- Close all files and deallocate arrays 422 DO id = 0, danz-1 423 CLOSE ( id+110 ) 424 ENDDO 425 CLOSE ( 2 ) 426 DEALLOCATE ( eta, ho, hu, pf ) 427 ENDIF 428 429 ! 430 !-- Close the NetCDF file 431 IF ( netcdf_output .AND. danz /= 0 ) THEN 432 #if defined( __netcdf ) 433 IF ( netcdf_0 ) THEN 434 nc_stat = NF90_CLOSE( id_set(0) ) 435 IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 11 ) 436 ENDIF 437 IF ( netcdf_1 ) THEN 438 nc_stat = NF90_CLOSE( id_set(1) ) 439 IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 12 ) 440 ENDIF 441 #endif 442 ENDIF 443 444 ! 445 !-- Choose the next cross-section 446 SELECT CASE ( modus ) 447 CASE ( 'XY' ) 448 modus = 'XZ' 449 CASE ( 'XZ' ) 450 modus = 'YZ' 451 CASE ( 'YZ' ) 452 modus = 'no' 453 END SELECT 123 454 124 455 ENDDO 125 456 126 ! 127 !-- Inquire whether an iso2d parameter file exists 128 INQUIRE( FILE='PLOT2D_' // modus // '_GLOBAL', EXIST=iso2d_output ) 457 458 ! 459 !-- Combine the 3D-arrays 460 461 ! 462 !-- Inquire whether an avs fld file exists 463 INQUIRE( FILE='PLOT3D_FLD'//TRIM( model_string ), EXIST=avs_output ) 129 464 130 465 ! 131 466 !-- Inquire whether a NetCDF file exists 132 INQUIRE( FILE='DATA_ 2D_' // modus // '_NETCDF', EXIST=netcdf_0 )467 INQUIRE( FILE='DATA_3D_NETCDF'//TRIM( model_string ), EXIST=netcdf_0 ) 133 468 134 469 ! 135 470 !-- Inquire whether a NetCDF file for time-averaged data exists 136 INQUIRE( FILE='DATA_ 2D_' // modus // '_AV_NETCDF', EXIST=netcdf_1 )471 INQUIRE( FILE='DATA_3D_AV_NETCDF'//TRIM( model_string ), EXIST=netcdf_1 ) 137 472 138 473 IF ( netcdf_0 .OR. netcdf_1 ) THEN … … 143 478 144 479 ! 480 !-- Check, if file from PE0 exists 481 danz = 0 482 WRITE (id_string,'(I4.4)') danz 483 INQUIRE ( & 484 FILE='PLOT3D_DATA'//TRIM( model_string )//'_'//TRIM( id_string ), & 485 EXIST=found ) 486 487 ! 488 !-- Combination only works, if data are not compressed. In that case, 489 !-- PALM created a flag file (PLOT3D_COMPRESSED) 490 INQUIRE ( FILE='PLOT3D_COMPRESSED'//TRIM( model_string ), & 491 EXIST=compressed ) 492 493 ! 494 !-- Find out the number of files and open them 495 DO WHILE ( found .AND. .NOT. compressed ) 496 497 OPEN ( danz+110, & 498 FILE='PLOT3D_DATA'//TRIM( model_string )//'_'//TRIM(id_string), & 499 FORM='UNFORMATTED') 500 danz = danz + 1 501 WRITE (id_string,'(I4.4)') danz 502 INQUIRE ( & 503 FILE='PLOT3D_DATA'//TRIM( model_string )//'_'//TRIM(id_string), & 504 EXIST=found ) 505 506 ENDDO 507 508 ! 145 509 !-- Info-output 146 PRINT*, ' '510 PRINT*, ' ' 147 511 PRINT*, '*** combine_plot_fields ***' 148 512 #if defined( __netcdf ) … … 155 519 #endif 156 520 IF ( danz /= 0 ) THEN 157 PRINT*, ' ',modus,'-section:', danz, ' file(s) found'521 PRINT*, ' 3D-data: ', danz, ' file(s) found' 158 522 ELSE 159 PRINT*, ' no ', modus, '-section data available' 523 IF ( found .AND. compressed ) THEN 524 PRINT*, '+++ no 3D-data processing, since data are compressed' 525 ELSE 526 PRINT*, ' no 3D-data file available' 527 ENDIF 160 528 ENDIF 161 529 … … 170 538 !-- Open NetCDF dataset 171 539 IF ( av == 0 ) THEN 172 filename = 'DATA_ 2D_' // modus // '_NETCDF'540 filename = 'DATA_3D_NETCDF'//TRIM( model_string ) 173 541 ELSE 174 filename = 'DATA_ 2D_' // modus // '_AV_NETCDF'542 filename = 'DATA_3D_AV_NETCDF'//TRIM( model_string ) 175 543 ENDIF 176 544 nc_stat = NF90_OPEN( filename, NF90_WRITE, id_set(av) ) 177 IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 1 ) 545 IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 13 ) 546 178 547 179 548 ! … … 182 551 var_list(av) = ' ' ! GET_ATT does not assign trailing blanks 183 552 nc_stat = NF90_GET_ATT( id_set(av), NF90_GLOBAL, 'VAR_LIST', & 184 185 IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 2)553 var_list(av) ) 554 IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 14 ) 186 555 187 556 ! 188 557 !-- Inquire id of the time coordinate variable 189 558 nc_stat = NF90_INQ_VARID( id_set(av), 'time', id_var_time(av) ) 190 IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 3)559 IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 15 ) 191 560 192 561 ! … … 199 568 200 569 ! 201 !-- Extract the variable names from the list and inquire their 202 !-- NetCDFIDs570 !-- Extract the variable names from the list and inquire their NetCDF 571 !-- IDs 203 572 pos = INDEX( var_list(av), ';' ) 204 573 ! … … 214 583 ! 215 584 !-- Get variable ID from name 585 ! print*, '*** find id for "',TRIM( var_name ),'" begin' 216 586 nc_stat = NF90_INQ_VARID( id_set(av), TRIM( var_name ), & 217 id_var(av,i) ) 218 IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 4 ) 219 220 ! 221 !-- Get number of x/y/z levels for that variable 222 nc_stat = NF90_INQUIRE_VARIABLE( id_set(av), id_var(av,i), & 223 dimids = id_dims_loc ) 224 IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 5 ) 225 id_dims(av,:) = id_dims_loc 226 227 ! 228 !-- Inquire dimension ID 229 DO j = 1, 4 230 nc_stat = NF90_INQUIRE_DIMENSION( id_set(av), id_dims(av,j),& 231 dimname, levels(av,i) ) 232 IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 6 ) 233 234 IF ( modus == 'XY' .AND. INDEX(dimname, 'z') /= 0 ) EXIT 235 IF ( modus == 'XZ' .AND. INDEX(dimname, 'y') /= 0 ) EXIT 236 IF ( modus == 'YZ' .AND. INDEX(dimname, 'x') /= 0 ) EXIT 237 ENDDO 587 id_var(av,i) ) 588 IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 16 ) 589 ! print*, '*** find id for "',TRIM( var_name ),'" end' 238 590 239 591 ENDDO 240 592 241 ENDDO ! av = 0,1593 ENDDO ! av=0,1 242 594 243 595 ENDIF … … 245 597 246 598 ! 247 !-- Read the arrays, as long as the end of the file is reached 248 fanz = 0 249 current_level = 1 250 current_var = 999999999 251 599 !-- Read arrays, until the end of the file is reached 600 current_var = 999999999 601 fanz = 0 252 602 DO WHILE ( danz /= 0 ) 253 603 254 604 ! 255 !-- Loop over all files (reading data of the subdomains)605 !-- Loop over all files 256 606 DO id = 0, danz-1 257 607 ! 258 608 !-- File from PE0 contains special information at the beginning, 259 !-- concerning the lower and upper indices of the total-domain used 260 !-- in PALM (nxag, nxeg, nyag, nyeg) and the lower and upper 261 !-- indices of the array to be writte by this routine (nxa, nxe, nya, 262 !-- nye). Usually in the horizontal directions nxag=-1 and nxa=0 263 !-- while all other variables have the same value (i.e. nxeg=nxe). 264 !-- Allocate necessary arrays, open the output file and write 265 !-- the coordinate informations needed by ISO2D. 609 !-- concerning the lower and upper indices of the total-domain used in 610 !-- PALM (nxag, nxeg, nyag, nyeg, nzag, nzeg) and the lower and upper 611 !-- indices of the array to be written by this routine (nxa, nxe, nya, 612 !-- nye, nza, nze). Usually nxag=-1 and nxa=0, nyag=-1 and nya=0, 613 !-- nzeg=nz and nze=nz_plot3d. 614 !-- Allocate necessary array and open the output file. 266 615 IF ( id == 0 .AND. fanz(0) == 0 .AND. fanz(1) == 0 ) THEN 267 READ ( id+110 ) nxag, nxeg, nyag, nyeg 268 READ ( id+110 ) nxa, nxe, nya, nye 269 ALLOCATE ( eta(nya:nye), ho(nxa:nxe), hu(nxa:nxe), & 270 pf(nxag:nxeg,nyag:nyeg) ) 271 READ ( id+110 ) dx, eta, hu, ho 272 273 IF ( iso2d_output ) THEN 274 OPEN ( 2, FILE='PLOT2D_'//modus, FORM='UNFORMATTED' ) 275 WRITE ( 2 ) dx, eta, hu, ho 616 READ ( id+110 ) nxag, nxeg, nyag, nyeg, nzag, nzeg 617 READ ( id+110 ) nxa, nxe, nya, nye, nza, nze 618 ALLOCATE ( pf3d(nxag:nxeg,nyag:nyeg,nzag:nzeg) ) 619 IF ( avs_output ) THEN 620 OPEN ( 2, FILE='PLOT3D_DATA'//TRIM( model_string ), & 621 FORM='UNFORMATTED' ) 276 622 ENDIF 277 623 ENDIF 624 278 625 ! 279 626 !-- Read output time 280 627 IF ( netcdf_output .AND. id == 0 ) THEN 281 628 IF ( netcdf_1 ) THEN 282 READ ( id+110, END=99 8) simulated_time, time_step, av629 READ ( id+110, END=999 ) simulated_time, time_step, av 283 630 ELSE 284 631 ! 285 632 !-- For compatibility with earlier PALM versions 286 READ ( id+110, END=99 8) simulated_time, time_step633 READ ( id+110, END=999 ) simulated_time, time_step 287 634 av = 0 288 635 ENDIF 289 636 ENDIF 290 ! 291 !-- Read subdomain indices 292 READ ( id+110, END=998 ) xa, xe, ya, ye 293 ! 294 !-- IF the PE made no output (in case that no part of the 295 !-- cross-section is situated on this PE), indices have the 296 !-- value -1 297 IF ( .NOT. ( xa == -1 .AND. xe == -1 .AND. & 298 ya == -1 .AND. ye == -1 ) ) THEN 299 ! 300 !-- Read the subdomain grid-point values 301 READ ( id+110 ) pf(xa:xe,ya:ye) 302 ENDIF 637 638 ! 639 !-- Read subdomain indices and grid point values 640 READ ( id+110, END=999 ) xa, xe, ya, ye, za, ze 641 READ ( id+110 ) pf3d(xa:xe,ya:ye,za:ze) 303 642 IF ( id == 0 ) fanz(av) = fanz(av) + 1 304 643 305 644 ENDDO 306 ! 307 !-- Write the data of the total domain cross-section 308 IF ( iso2d_output ) WRITE ( 2 ) pf(nxa:nxe,nya:nye) 645 646 ! 647 !-- Write data of the total domain 648 IF ( avs_output ) WRITE ( 2 ) pf3d(nxa:nxe,nya:nye,nza:nze) 309 649 310 650 ! … … 317 657 current_var(av) = 1 318 658 nc_stat = NF90_PUT_VAR( id_set(av), id_var_time(av), & 319 (/ simulated_time /), & 320 start = (/ time_step /), & 321 count = (/ 1 /) ) 322 IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 7 ) 323 ENDIF 324 325 ! 326 !-- Now write the data; this is mode dependent 327 SELECT CASE ( modus ) 328 329 CASE ( 'XY' ) 330 nc_stat = NF90_PUT_VAR( id_set(av), & 331 id_var(av,current_var(av)), & 332 pf(nxa:nxe,nya:nye), & 333 start = (/ 1, 1, current_level(av), time_step /), & 334 count = (/ nxe-nxa+1, nye-nya+1, 1, 1 /) ) 335 IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 8 ) 336 337 CASE ( 'XZ' ) 338 nc_stat = NF90_PUT_VAR( id_set(av), & 339 id_var(av,current_var(av)), & 340 pf(nxa:nxe,nya:nye), & 341 start = (/ 1, current_level(av), 1, time_step /), & 342 count = (/ nxe-nxa+1, 1, nye-nya+1, 1 /) ) 343 IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 9 ) 344 345 CASE ( 'YZ' ) 346 nc_stat = NF90_PUT_VAR( id_set(av), & 347 id_var(av,current_var(av)), & 348 pf(nxa:nxe,nya:nye), & 349 start = (/ current_level(av), 1, 1, time_step /), & 350 count = (/ 1, nxe-nxa+1, nye-nya+1, 1 /) ) 351 IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 10 ) 352 353 END SELECT 354 355 ! 356 !-- Data is written, check if max level is reached 357 current_level(av) = current_level(av) + 1 358 IF ( current_level(av) > levels(av,current_var(av)) ) THEN 359 current_level(av) = 1 360 current_var(av) = current_var(av) + 1 361 ENDIF 362 363 ENDIF 364 #endif 659 (/ simulated_time /),& 660 start = (/ time_step /), count = (/ 1 /) ) 661 IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 17 ) 662 ENDIF 663 664 ! 665 !-- Now write the data 666 nc_stat = NF90_PUT_VAR( id_set(av), id_var(av,current_var(av)), & 667 pf3d(nxa:nxe,nya:nye,nza:nze), & 668 start = (/ 1, 1, 1, time_step /), & 669 count = (/ nxe-nxa+1, nye-nya+1, nze-nza+1, 1 /) ) 670 IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 18 ) 671 672 current_var(av) = current_var(av) + 1 673 674 #endif 675 ENDIF 365 676 366 677 ENDDO 367 678 368 99 8IF ( danz /= 0 ) THEN369 ! 370 !-- Print the number of thearrays processed679 999 IF ( danz /= 0 ) THEN 680 ! 681 !-- Print the number of arrays processed 371 682 WRITE (*,'(16X,I4,A)') fanz(0)+fanz(1), ' array(s) processed' 372 683 IF ( fanz(1) /= 0 ) THEN 373 684 WRITE (*,'(16X,I4,A)') fanz(1), ' array(s) are time-averaged' 374 685 ENDIF 375 376 ! 377 !-- Close all files and deallocate arrays 686 ! 687 !-- Close all files and deallocate array 378 688 DO id = 0, danz-1 379 689 CLOSE ( id+110 ) 380 690 ENDDO 381 691 CLOSE ( 2 ) 382 DEALLOCATE ( eta, ho, hu, pf ) 692 DEALLOCATE ( pf3d ) 693 ! 694 !-- Close the NetCDF file 695 IF ( netcdf_output ) THEN 696 #if defined( __netcdf ) 697 IF ( netcdf_0 ) THEN 698 nc_stat = NF90_CLOSE( id_set(0) ) 699 IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 19 ) 700 ENDIF 701 IF ( netcdf_1 ) THEN 702 nc_stat = NF90_CLOSE( id_set(1) ) 703 IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 20 ) 704 ENDIF 705 #endif 706 ENDIF 383 707 ENDIF 384 708 385 ! 386 !-- Close the NetCDF file 387 IF ( netcdf_output .AND. danz /= 0 ) THEN 388 #if defined( __netcdf ) 389 IF ( netcdf_0 ) THEN 390 nc_stat = NF90_CLOSE( id_set(0) ) 391 IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 11 ) 392 ENDIF 393 IF ( netcdf_1 ) THEN 394 nc_stat = NF90_CLOSE( id_set(1) ) 395 IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 12 ) 396 ENDIF 397 #endif 398 ENDIF 399 400 ! 401 !-- Choose the next cross-section 402 SELECT CASE ( modus ) 403 CASE ( 'XY' ) 404 modus = 'XZ' 405 CASE ( 'XZ' ) 406 modus = 'YZ' 407 CASE ( 'YZ' ) 408 modus = 'no' 409 END SELECT 410 411 ENDDO 412 413 414 ! 415 !-- Combine the 3D-arrays 416 417 ! 418 !-- Inquire whether an avs fld file exists 419 INQUIRE( FILE='PLOT3D_FLD', EXIST=avs_output ) 420 421 ! 422 !-- Inquire whether a NetCDF file exists 423 INQUIRE( FILE='DATA_3D_NETCDF', EXIST=netcdf_0 ) 424 425 ! 426 !-- Inquire whether a NetCDF file for time-averaged data exists 427 INQUIRE( FILE='DATA_3D_AV_NETCDF', EXIST=netcdf_1 ) 428 429 IF ( netcdf_0 .OR. netcdf_1 ) THEN 430 netcdf_output = .TRUE. 431 ELSE 432 netcdf_output = .FALSE. 433 ENDIF 434 435 ! 436 !-- Check, if file from PE0 exists 437 danz = 0 438 WRITE (id_char,'(I4.4)') danz 439 INQUIRE ( FILE='PLOT3D_DATA_'//TRIM( id_char ), EXIST=found ) 440 441 ! 442 !-- Combination only works, if data are not compressed. In that case, 443 !-- PALM created a flag file (PLOT3D_COMPRESSED) 444 INQUIRE ( FILE='PLOT3D_COMPRESSED', EXIST=compressed ) 445 446 ! 447 !-- Find out the number of files and open them 448 DO WHILE ( found .AND. .NOT. compressed ) 449 450 OPEN ( danz+110, FILE='PLOT3D_DATA_'//TRIM( id_char ), & 451 FORM='UNFORMATTED') 452 danz = danz + 1 453 WRITE (id_char,'(I4.4)') danz 454 INQUIRE ( FILE='PLOT3D_DATA_'//TRIM( id_char ), EXIST=found ) 455 456 ENDDO 457 458 ! 459 !-- Info-output 460 PRINT*, ' ' 461 PRINT*, '*** combine_plot_fields ***' 462 #if defined( __netcdf ) 463 IF ( netcdf_output ) PRINT*, ' NetCDF output enabled' 464 #else 465 IF ( netcdf_output ) THEN 466 PRINT*, '--- Sorry, no NetCDF support on this host' 467 netcdf_output = .FALSE. 468 ENDIF 469 #endif 470 IF ( danz /= 0 ) THEN 471 PRINT*, ' 3D-data: ', danz, ' file(s) found' 472 ELSE 473 IF ( found .AND. compressed ) THEN 474 PRINT*, '+++ no 3D-data processing, since data are compressed' 475 ELSE 476 PRINT*, ' no 3D-data file available' 477 ENDIF 478 ENDIF 479 480 IF ( netcdf_output .AND. danz /= 0 ) THEN 481 #if defined( __netcdf ) 482 DO av = 0, 1 483 484 IF ( av == 0 .AND. .NOT. netcdf_0 ) CYCLE 485 IF ( av == 1 .AND. .NOT. netcdf_1 ) CYCLE 486 487 ! 488 !-- Open NetCDF dataset 489 IF ( av == 0 ) THEN 490 filename = 'DATA_3D_NETCDF' 491 ELSE 492 filename = 'DATA_3D_AV_NETCDF' 493 ENDIF 494 nc_stat = NF90_OPEN( filename, NF90_WRITE, id_set(av) ) 495 IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 13 ) 496 497 498 ! 499 !-- Get the list of variables (order of variables corresponds with the 500 !-- order of data on the binary file) 501 var_list(av) = ' ' ! GET_ATT does not assign trailing blanks 502 nc_stat = NF90_GET_ATT( id_set(av), NF90_GLOBAL, 'VAR_LIST', & 503 var_list(av) ) 504 IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 14 ) 505 506 ! 507 !-- Inquire id of the time coordinate variable 508 nc_stat = NF90_INQ_VARID( id_set(av), 'time', id_var_time(av) ) 509 IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 15 ) 510 511 ! 512 !-- Count number of variables; there is one more semicolon in the string 513 !-- than variable names 514 num_var(av) = -1 515 DO i = 1, LEN( var_list(av) ) 516 IF ( var_list(av)(i:i) == ';' ) num_var(av) = num_var(av) + 1 517 ENDDO 518 519 ! 520 !-- Extract the variable names from the list and inquire their NetCDF IDs 521 pos = INDEX( var_list(av), ';' ) 522 ! 523 !-- Loop over all variables 524 DO i = 1, num_var(av) 525 526 ! 527 !-- Extract variable name from list 528 var_list(av) = var_list(av)(pos+1:) 529 pos = INDEX( var_list(av), ';' ) 530 var_name = var_list(av)(1:pos-1) 531 532 ! 533 !-- Get variable ID from name 534 ! print*, '*** find id for "',TRIM( var_name ),'" begin' 535 nc_stat = NF90_INQ_VARID( id_set(av), TRIM( var_name ), & 536 id_var(av,i) ) 537 IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 16 ) 538 ! print*, '*** find id for "',TRIM( var_name ),'" end' 539 540 ENDDO 541 542 ENDDO ! av=0,1 543 544 ENDIF 545 #endif 546 547 ! 548 !-- Read arrays, until the end of the file is reached 549 current_var = 999999999 550 fanz = 0 551 DO WHILE ( danz /= 0 ) 552 553 ! 554 !-- Loop over all files 555 DO id = 0, danz-1 556 ! 557 !-- File from PE0 contains special information at the beginning, 558 !-- concerning the lower and upper indices of the total-domain used 559 !-- in PALM (nxag, nxeg, nyag, nyeg, nzag, nzeg) and the lower and upper 560 !-- indices of the array to be written by this routine (nxa, nxe, nya, 561 !-- nye, nza, nze). Usually nxag=-1 and nxa=0, nyag=-1 and nya=0, 562 !-- nzeg=nz and nze=nz_plot3d. 563 !-- Allocate necessary array and open the output file. 564 IF ( id == 0 .AND. fanz(0) == 0 .AND. fanz(1) == 0 ) THEN 565 READ ( id+110 ) nxag, nxeg, nyag, nyeg, nzag, nzeg 566 READ ( id+110 ) nxa, nxe, nya, nye, nza, nze 567 ALLOCATE ( pf3d(nxag:nxeg,nyag:nyeg,nzag:nzeg) ) 568 IF ( avs_output ) THEN 569 OPEN ( 2, FILE='PLOT3D_DATA', FORM='UNFORMATTED' ) 570 ENDIF 571 ENDIF 572 573 ! 574 !-- Read output time 575 IF ( netcdf_output .AND. id == 0 ) THEN 576 IF ( netcdf_1 ) THEN 577 READ ( id+110, END=999 ) simulated_time, time_step, av 578 ELSE 579 ! 580 !-- For compatibility with earlier PALM versions 581 READ ( id+110, END=999 ) simulated_time, time_step 582 av = 0 583 ENDIF 584 ENDIF 585 586 ! 587 !-- Read subdomain indices and grid point values 588 READ ( id+110, END=999 ) xa, xe, ya, ye, za, ze 589 READ ( id+110 ) pf3d(xa:xe,ya:ye,za:ze) 590 IF ( id == 0 ) fanz(av) = fanz(av) + 1 591 592 ENDDO 593 594 ! 595 !-- Write data of the total domain 596 IF ( avs_output ) WRITE ( 2 ) pf3d(nxa:nxe,nya:nye,nza:nze) 597 598 ! 599 !-- Write same data in NetCDF format 600 IF ( netcdf_output ) THEN 601 #if defined( __netcdf ) 602 ! 603 !-- Check if a new time step has begun; if yes write data to time axis 604 IF ( current_var(av) > num_var(av) ) THEN 605 current_var(av) = 1 606 nc_stat = NF90_PUT_VAR( id_set(av), id_var_time(av), & 607 (/ simulated_time /),& 608 start = (/ time_step /), count = (/ 1 /) ) 609 IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 17 ) 610 ENDIF 611 612 ! 613 !-- Now write the data 614 nc_stat = NF90_PUT_VAR( id_set(av), id_var(av,current_var(av)), & 615 pf3d(nxa:nxe,nya:nye,nza:nze), & 616 start = (/ 1, 1, 1, time_step /), & 617 count = (/ nxe-nxa+1, nye-nya+1, nze-nza+1, 1 /) ) 618 IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 18 ) 619 620 current_var(av) = current_var(av) + 1 621 622 #endif 623 ENDIF 624 625 ENDDO 626 627 999 IF ( danz /= 0 ) THEN 628 ! 629 !-- Print the number of arrays processed 630 WRITE (*,'(16X,I4,A)') fanz(0)+fanz(1), ' array(s) processed' 631 IF ( fanz(1) /= 0 ) THEN 632 WRITE (*,'(16X,I4,A)') fanz(1), ' array(s) are time-averaged' 633 ENDIF 634 ! 635 !-- Close all files and deallocate array 636 DO id = 0, danz-1 637 CLOSE ( id+110 ) 638 ENDDO 639 CLOSE ( 2 ) 640 DEALLOCATE ( pf3d ) 641 ! 642 !-- Close the NetCDF file 643 IF ( netcdf_output ) THEN 644 #if defined( __netcdf ) 645 IF ( netcdf_0 ) THEN 646 nc_stat = NF90_CLOSE( id_set(0) ) 647 IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 19 ) 648 ENDIF 649 IF ( netcdf_1 ) THEN 650 nc_stat = NF90_CLOSE( id_set(1) ) 651 IF ( nc_stat /= NF90_NOERR ) CALL handle_netcdf_error( 20 ) 652 ENDIF 653 #endif 654 ENDIF 655 ENDIF 709 ENDDO ! models 656 710 657 711
Note: See TracChangeset
for help on using the changeset viewer.