00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 subroutine psmile_open_file_byid (id_varid,id_taskid,current_date,ierror)
00012
00013
00014
00015
00016 use PRISM_Constants
00017 use PSMILe_SMIOC, only : sga_smioc_transi
00018 use PSMILe, dummy_interface => PSMILE_Open_File_byid
00019 use PRISM_calendar
00020 use PSMILE_IO_UTILS
00021 implicit none
00022
00023
00024
00025 Integer, Intent (In) :: id_varid
00026 Integer, Intent (In) :: id_taskid
00027 Type(PRISM_Time_Struct),Intent (In) :: current_date
00028
00029
00030
00031
00032 Integer, Intent (Out) :: ierror
00033
00034
00035
00036
00037 integer :: ierrp(3)
00038 integer :: iicomp_id
00039 integer :: il_initial_date(6)
00040 integer :: il_filesize
00041 integer :: fullsize
00042 integer :: il_no_of_files,il_no,il_i,il_j
00043 integer :: il_natts,il_nvars,il_ntimes
00044 ,il_ndims,iloc,il_grid_id
00045 integer :: il_axes(3)
00046 integer :: il_x,il_y
00047 integer :: il_smioc_loc,il_transiouts
00048 logical :: ll_exist,ll_base,ll_restart
00049 character(len=max_name) :: cl_filename,cl_date
00050 ,cl_time,cl_zone,cl_name,cl_uname
00051 character(len=4) :: cl_label
00052 character(len=max_name),allocatable :: cl_files_found(:)
00053 Type(IO_Data),Pointer :: pl_io_info
00054 Type(PRISM_Time_Struct) :: ljobstart
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 Character(len=len_cvs_string),save :: open_by_id=
00087 '$Id: psmile_open_file_byid.F90 2687 2010-10-28 15:15:52Z coquart $'
00088
00089 ierror = 0
00090 #ifdef __PSMILE_WITH_IO
00091 #ifdef VERBOSE
00092 print*,trim(ch_id),' : PSMILe_open_file_byid: start'
00093 call psmile_flushstd
00094 print*,trim(ch_id),' : PSMILe_open_file_byid: date', current_date
00095 call psmile_flushstd
00096
00097 #endif
00098 if (.not.associated(Fields)) then
00099
00100 ierror = PRISM_Error_Internal
00101 call psmile_error ( ierror, 'Fields not allocated ', &
00102 ierrp, 0, __FILE__, __LINE__ )
00103 endif
00104
00105 if ( (id_varid .gt. Size(Fields)).or.(id_varid.lt.1) .or. &
00106 (Fields(id_varid)%status .eq. PSMILe_Status_undefined) ) then
00107
00108 ierror = PRISM_Error_Internal
00109 call psmile_error ( ierror, 'Fields(varid) status undefined ', &
00110 ierrp, 0, __FILE__, __LINE__ )
00111 endif
00112
00113 if (.not.associated(Fields(id_varid)%io_chan_infos)) then
00114
00115 ierror = PRISM_Error_Internal
00116 call psmile_error ( ierror, 'Fields has no I/O infos! ', &
00117 ierrp, 0, __FILE__, __LINE__ )
00118 endif
00119
00120
00121
00122
00123 if(id_taskid .le. size(Fields(id_varid)%io_task_lookup)) then
00124
00125 il_i=Fields(id_varid)%io_task_lookup(id_taskid)
00126
00127 else
00128
00129 ierror = PRISM_Error_IO_Meta
00130 ierrp (1) = id_taskid
00131 call psmile_error ( ierror &
00132 , 'Task id out of range! ', &
00133 ierrp, 1, __FILE__, __LINE__ )
00134 return
00135
00136 endif
00137
00138 if (il_i.gt.0) then
00139
00140 Fields(id_varid)%io_infos => Fields(id_varid)%io_chan_infos(il_i)
00141
00142 else
00143 ierror = PRISM_Error_IO_Meta
00144 ierrp (1) = id_taskid
00145 call psmile_error ( ierror &
00146 , 'Negative task id! ', &
00147 ierrp, 1, __FILE__, __LINE__ )
00148 return
00149 endif
00150
00151 pl_io_info => Fields(id_varid)%io_infos
00152
00153
00154
00155
00156
00157 il_transiouts=0
00158 il_smioc_loc=Fields(id_varid)%smioc_loc
00159
00160 if(associated(sga_smioc_transi(il_smioc_loc)%sga_transi_out)) &
00161 il_transiouts=size(sga_smioc_transi(il_smioc_loc)%sga_transi_out)
00162 if(id_taskid .gt. 0 ) then
00163
00164 if(id_taskid.gt.2*il_transiouts+1 &
00165 .and.id_taskid.le.4*il_transiouts+1) then
00166 ll_restart=.true.
00167 #ifdef VERBOSE
00168 print*,trim(ch_id),' : PSMILe_open_file_byid: Open of restart files!'
00169 call psmile_flushstd
00170 #endif
00171 endif
00172
00173 else
00174
00175 ierror = PRISM_Error_IO_Meta
00176 ierrp (1) = id_taskid
00177 call psmile_error ( ierror &
00178 , 'Task id out of range! ', &
00179 ierrp, 1, __FILE__, __LINE__ )
00180 endif
00181
00182 iicomp_id=Fields(id_varid)%comp_id
00183
00184 if(.not.associated(IO_Comps_infos(iicomp_id)%pelist)) then
00185 ierror=PRISM_Error_IO_Domain
00186 ierrp(1)=iicomp_id
00187 call psmile_error ( ierror &
00188 ,'pelist for component does not exist!' &
00189 ,ierrp, 1, __FILE__,__LINE__)
00190 endif
00191
00192 call mpp_set_current_pelist(IO_Comps_infos(iicomp_id)%pelist)
00193
00194
00195 Select Case(pl_io_info%action)
00196
00197 Case (MPP_RDONLY)
00198 #ifdef VERBOSE
00199 print*,trim(ch_id),' : PSMILe_open_file_byid: open for reading'
00200 call psmile_flushstd
00201 #endif
00202
00203
00204
00205
00206 if(associated(Fields(id_varid)%io_infos%related_ids)) then
00207 fullsize=size(Fields(id_varid)%io_infos%related_ids)
00208 if(fullsize.gt.1) then
00209 do il_i=1,fullsize
00210 if(id_varid.eq. Fields(id_varid)%io_infos%related_ids(il_i)) exit
00211 enddo
00212 if(il_i.gt.1) return
00213 endif
00214 endif
00215
00216 If(len(trim(pl_io_info%filename)).eq.0) then
00217 ierror=PRISM_Error_IO_Open
00218 call psmile_error(ierror, &
00219 'No filename on read given!!!', &
00220 ierrp,0, __FILE__, __LINE__)
00221 endif
00222
00223
00224
00225 call psmile_io_check_basename(trim(pl_io_info%filename),'.nc' &
00226 ,ll_base,ierror)
00227 If(ll_base) then
00228 #ifdef VERBOSE
00229 print*,trim(ch_id),' : PSMILe_open_file_byid: basename given'
00230 call psmile_flushstd
00231 #endif
00232
00233 il_initial_date(1)=current_date%year
00234 il_initial_date(2)=current_date%month
00235 il_initial_date(3)=current_date%day
00236 il_initial_date(4)=current_date%hour
00237 il_initial_date(5)=current_date%minute
00238 il_initial_date(6)=current_date%second
00239 call combine_with_date(pl_io_info%filename,'in' &
00240 ,il_initial_date,cl_filename)
00241
00242
00243
00244
00245 if(pl_io_info%threading .eq. MPP_MULTI &
00246 .and.pl_io_info%fileset.EQ.MPP_MULTI) then
00247 write(cl_label,'(i4.4)') mpp_pe()
00248 cl_filename=trim(cl_filename)//'.'//trim(cl_label)
00249 endif
00250
00251
00252
00253
00254 #ifdef VERBOSE
00255 print*,trim(ch_id),' : PSMILe_open_file_byid: Looking for ' &
00256 ,trim(pl_io_info%filename)//'_in','*'
00257 call psmile_flushstd
00258 #endif
00259 call psmile_io_scandir_no_of_files(trim(pl_io_info%filename)//'_in' &
00260 ,il_no_of_files,ierror)
00261
00262 if(il_no_of_files.eq.0) then
00263 if(ll_restart) then
00264 ierror=PRISM_UNDEFINED
00265 ierrp(1) = 0
00266 call psmile_warning(ierror, &
00267 'No match for basename '//trim(pl_io_info%filename)//'_in' &
00268 ,ierrp, 1, __FILE__, __LINE__)
00269 return
00270 else
00271 ierror=PRISM_Error_IO_Open
00272 call psmile_error(ierror, &
00273 'No match for basename '//trim(pl_io_info%filename)//'_in' &
00274 ,ierrp,0, __FILE__, __LINE__)
00275 endif
00276 endif
00277
00278
00279
00280 allocate(cl_files_found(1:il_no_of_files),stat=ierror)
00281 cl_files_found(1:il_no_of_files)=' '
00282
00283 if(ierror.ne.0) then
00284 ierror=PRISM_Error_IO_Open
00285 call psmile_error(ierror, &
00286 'Allocation of file table failed!' &
00287 ,ierrp,0, __FILE__, __LINE__)
00288
00289 endif
00290
00291 call psmile_io_scandir(trim(pl_io_info%filename)//'_in' &
00292 ,cl_files_found,il_no_of_files &
00293 ,il_no &
00294 ,ierror)
00295
00296
00297
00298 #ifdef VERBOSE
00299 print*,trim(ch_id),' : PSMILe_open_file_byid: Trying to match ' &
00300 ,' filename ',trim (cl_filename)
00301 call psmile_flushstd
00302 #endif
00303 il_i=1
00304 do while(trim(cl_filename).lt.trim(cl_files_found(il_i)))
00305 il_i=il_i+1
00306 if(il_i.gt.il_no_of_files) exit
00307 enddo
00308
00309 if(il_i.gt.il_no_of_files) then
00310 if(ll_restart) then
00311 ierror=PRISM_UNDEFINED
00312 ierrp(1) = 0
00313 call psmile_warning(ierror, &
00314 'Could not find a matching file for '//trim(cl_filename), &
00315 ierrp, 1, __FILE__, __LINE__)
00316 return
00317 else
00318 ierror=PRISM_Error_IO_Open
00319 call psmile_error(ierror, &
00320 'Could not find a matching file for '//trim(cl_filename), &
00321 ierrp,0, __FILE__, __LINE__)
00322 endif
00323 endif
00324 #ifdef VERBOSE
00325 print*,trim(ch_id),' : PSMILe_open_file_byid: Found best match for ' &
00326 ,' filename ',trim (cl_filename), ' as '
00327 print*, trim(cl_files_found(il_i))
00328 call psmile_flushstd
00329 #endif
00330
00331 do il_j=1,len(trim(cl_filename))
00332 cl_filename(il_j:il_j)=' '
00333 enddo
00334
00335 cl_filename=trim(cl_files_found(il_i))
00336
00337
00338 else
00339
00340
00341 cl_filename=pl_io_info%filename
00342
00343 endif
00344
00345
00346
00347
00348
00349 ll_exist=pl_io_info%opened
00350 if(.not.ll_base.and.ll_exist) then
00351
00352
00353
00354
00355 ierror=PRISM_Error_IO_Open
00356 call psmile_error(ierror, &
00357 'Attempt to open file '//trim(cl_filename)//' multiple times!', &
00358 ierrp,0, __FILE__, __LINE__)
00359
00360 else if(ll_base.and.ll_exist) then
00361 call psmile_close_file_byid(id_varid,id_taskid,ierror)
00362 endif
00363
00364
00365
00366
00367 Inquire(file=trim(cl_filename),exist=ll_exist)
00368 if(.not.ll_exist) then
00369 if(ll_restart) then
00370 ierror=PRISM_UNDEFINED
00371 ierrp(1) = 0
00372 call psmile_warning(ierror, &
00373 'File '//trim(cl_filename)//' does not exist!', &
00374 ierrp, 1, __FILE__, __LINE__)
00375 return
00376 else
00377 ierror=PRISM_Error_IO_Open
00378 call psmile_error(ierror, &
00379 'File '//trim(cl_filename)//' does not exist!', &
00380 ierrp,0, __FILE__, __LINE__)
00381 endif
00382 endif
00383
00384
00385
00386
00387 if(pl_io_info%fileset .eq. MPP_MULTI) then
00388 cl_filename=cl_files_found(il_i)(1:len(trim(cl_files_found(il_i))) &
00389 -len(trim(cl_label))-1)
00390 endif
00391 #ifdef VERBOSE
00392 print*,trim(ch_id),' : PSMILe_open_file_byid: mpp_open:read: ' &
00393 ,id_varid,pl_io_info%file_unit,trim(cl_filename)
00394 call psmile_flushstd
00395 #endif
00396 call mpp_open(pl_io_info%file_unit,trim(cl_filename) &
00397 #ifdef __PARNETCDF
00398
00399 ,mpp_comm=IO_Apps_infos%comm &
00400 #endif
00401 ,action=pl_io_info%action &
00402 ,form=pl_io_info%format &
00403 ,threading=pl_io_info%threading &
00404 ,fileset=pl_io_info%fileset)
00405
00406 pl_io_info%opened=.true.
00407
00408
00409
00410 call mpp_get_info(pl_io_info%file_unit,il_ndims,il_nvars,il_natts &
00411 ,il_ntimes)
00412
00413 #ifdef VERBOSE
00414 print*,trim(ch_id),' : PSMILe_open_file_byid: mpp_get_info: ' &
00415 ,il_ndims,il_nvars,il_natts,il_ntimes
00416 call psmile_flushstd
00417 #endif
00418 if(il_ntimes.gt.0) then
00419 if(.not.associated(pl_io_info%p_mpp_io%atts) ) &
00420 allocate(pl_io_info%p_mpp_io%atts(il_natts),stat=ierror)
00421 if (ierror > 0) then
00422 ierrp (1) = ierror
00423 ierrp (2) = 1
00424 ierror = PRISM_Error_Alloc
00425 call psmile_error ( ierror, 'atts', &
00426 ierrp, 2, __FILE__, __LINE__ )
00427 return
00428 endif
00429
00430
00431 if(.not.associated(pl_io_info%p_mpp_io%anaxis) ) &
00432 allocate(pl_io_info%p_mpp_io%anaxis(il_ndims),stat=ierror)
00433 if (ierror > 0) then
00434 ierrp (1) = ierror
00435 ierrp (2) = 1
00436 ierror = PRISM_Error_Alloc
00437 call psmile_error ( ierror, 'anaxis', &
00438 ierrp, 2, __FILE__, __LINE__ )
00439 return
00440 endif
00441
00442 if(.not.associated(pl_io_info%p_mpp_io%field) ) &
00443 allocate(pl_io_info%p_mpp_io%field(il_nvars),stat=ierror)
00444 if (ierror > 0) then
00445 ierrp (1) = ierror
00446 ierrp (2) = 1
00447 ierror = PRISM_Error_Alloc
00448 call psmile_error ( ierror, 'field', &
00449 ierrp, 2, __FILE__, __LINE__ )
00450 return
00451 endif
00452 if(.not.associated(pl_io_info%p_cache) ) then
00453
00454
00455
00456
00457
00458 if(.not.allocated(iocache)) then
00459 allocate(iocache(1:16*Number_of_Fields_allocated))
00460 #ifdef PRISM_ASSERTION
00461 if(size(Fields(id_varid)%io_task_lookup) .gt. 16 ) then
00462 call psmile_assert (__FILE__, __LINE__, &
00463 "No. of I/O channels > 16")
00464 endif
00465 #endif
00466 do il_i=1,16*Number_of_Fields_allocated
00467 Nullify(iocache(il_i)%time_stamps)
00468 Nullify(iocache(il_i)%data_dble)
00469 Nullify(iocache(il_i)%data_real)
00470 Nullify(iocache(il_i)%data_int)
00471 enddo
00472
00473 endif
00474
00475 pl_io_info%p_cache =>iocache(id_taskid+16*(id_varid-1))
00476 if(associated(pl_io_info%p_cache%time_stamps) ) then
00477 deallocate(pl_io_info%p_cache%time_stamps)
00478 endif
00479
00480 allocate(pl_io_info%p_cache%time_stamps(0:il_ntimes),stat=ierror)
00481 pl_io_info%p_cache%llast=.false.
00482 pl_io_info%p_cache%ilast=0
00483
00484 if(ierror > 0) then
00485 ierrp (1) = ierror
00486 ierrp (2) = 1
00487 ierror = PRISM_Error_Alloc
00488 call psmile_error ( ierror, 'time_stamps', &
00489 ierrp, 2, __FILE__, __LINE__ )
00490
00491 endif
00492 endif
00493 else
00494 ierror=PRISM_Error_IO_Open
00495 call psmile_error(ierror, &
00496 'File '//trim(cl_filename)//' does not contain time stamps!!!', &
00497 ierrp,0, __FILE__, __LINE__)
00498 endif
00499
00500
00501
00502 call mpp_get_fields(pl_io_info%file_unit,pl_io_info%p_mpp_io%field(:))
00503 iloc=0
00504 pl_io_info%p_mpp_io%findex=PRISM_Undefined
00505
00506 il_i=len(trim(adjustl(Fields(id_varid)%io_infos%cfioname)))
00507 do il_j=1,il_nvars
00508 call mpp_get_atts(pl_io_info%p_mpp_io%field(il_j),name=cl_name &
00509 ,axes=pl_io_info%p_mpp_io%anaxis)
00510 if(cl_name(1:il_i).eq.Fields(id_varid)%io_infos%cfioname(1:il_i)) then
00511 iloc=iloc+1
00512 if(iloc.le.3) then
00513 pl_io_info%p_mpp_io%findex(iloc)=il_j
00514 else
00515 ierror=PRISM_Error_IO_Open
00516 call psmile_error(ierror, &
00517 'Found more than 3 ocurences of '// &
00518 trim(Fields(id_varid)%io_infos%cfioname), &
00519 ierrp,0, __FILE__, __LINE__)
00520
00521 endif
00522 endif
00523 enddo
00524
00525 if(iloc.eq.0) then
00526 ierror=PRISM_Error_IO_Open
00527 call psmile_error(ierror, &
00528 'The file '//trim(cl_filename)//' does not contain '// &
00529 trim(Fields(id_varid)%io_infos%cfioname), &
00530 ierrp,0, __FILE__, __LINE__)
00531 endif
00532
00533
00534
00535
00536
00537 do il_j=1,il_nvars
00538 call mpp_get_atts(pl_io_info%p_mpp_io%field(il_j),name=cl_name &
00539 ,axes=pl_io_info%p_mpp_io%anaxis)
00540 if (trim(cl_name) .eq. Fields(id_varid)%local_name) exit
00541 enddo
00542
00543 il_axes=PRISM_Undefined
00544 do il_j=1,il_ndims
00545 call mpp_get_atts(pl_io_info%p_mpp_io%anaxis(il_j),name=cl_name &
00546 ,len=il_axes(1))
00547 if(trim(cl_name).eq.'X') exit
00548 if(trim(cl_name).eq.'x') exit
00549 enddo
00550 #ifdef VERBOSE
00551 print*,trim(ch_id),' : PSMILe_open_file_byid:read: ' &
00552 ,'Length of x-axis ',il_axes(1)
00553 call psmile_flushstd
00554 #endif
00555
00556 do il_j=1,il_ndims
00557 call mpp_get_atts(pl_io_info%p_mpp_io%anaxis(il_j),name=cl_name &
00558 ,len=il_axes(2))
00559 if(trim(cl_name).eq.'Y') exit
00560 if(trim(cl_name).eq.'y') exit
00561 enddo
00562
00563 #ifdef VERBOSE
00564 print*,trim(ch_id),' : PSMILe_open_file_byid:read: ' &
00565 ,'Length of y-axis ',il_axes(2)
00566 call psmile_flushstd
00567 #endif
00568 do il_j=1,il_ndims
00569 call mpp_get_atts(pl_io_info%p_mpp_io%anaxis(il_j),name=cl_name &
00570 ,len=il_axes(3))
00571 if(trim(cl_name).eq.'Z') exit
00572 if(trim(cl_name).eq.'z') exit
00573 enddo
00574
00575 #ifdef VERBOSE
00576 print*,trim(ch_id),' : PSMILe_open_file_byid:read: ' &
00577 ,'Length of z-axis ',il_axes(3)
00578 call psmile_flushstd
00579 #endif
00580
00581 il_grid_id=Methods(Fields(id_varid)%method_id)%grid_id
00582
00583 do il_j=1,Grids(il_grid_id)%n_dim
00584
00585
00586
00587
00588 if(pl_io_info%fileset.EQ.MPP_SINGLE) then
00589 if(il_j.le.2) then
00590 call mpp_get_global_domain(pl_io_info%p_mpp_io%domain(1) &
00591 ,xsize=il_x,ysize=il_y)
00592 #ifdef VERBOSE
00593 print*,trim(ch_id),' : PSMILe_open_file_byid:read: ' &
00594 ,'Extents of domain ',il_x,il_y
00595 call psmile_flushstd
00596 #endif
00597 if(il_j.eq.1) il_i=il_x
00598 if(il_j.eq.2) il_i=il_y
00599 else
00600 il_i=Grids(il_grid_id)%grid_shape(2,il_j)- &
00601 Grids(il_grid_id)%grid_shape(1,il_j)+1
00602 endif
00603
00604 else
00605 il_i=Grids(il_grid_id)%grid_shape(2,il_j)- &
00606 Grids(il_grid_id)%grid_shape(1,il_j)+1
00607 endif
00608
00609 if(il_i.ne.il_axes(il_j)) then
00610
00611 ierror=PRISM_Error_IO_Open
00612
00613 ierrp(1)=il_j
00614 ierrp(2)=il_i
00615 ierrp(3)=il_axes(il_j)
00616 call psmile_error(ierror, &
00617 'The size of a axis does not match grids valid extent!'// &
00618 trim(Fields(id_varid)%io_infos%cfioname), &
00619 ierrp,3, __FILE__, __LINE__)
00620 endif
00621 enddo
00622
00623
00624
00625
00626 call mpp_get_times(pl_io_info%file_unit &
00627 ,pl_io_info%p_cache%time_stamps(1:il_ntimes))
00628 #ifdef VERBOSE
00629 print*,trim(ch_id),' : PSMILe_open_file_byid:read: time stamp(1) = ' &
00630 ,pl_io_info%p_cache%time_stamps(1),' time stamp(',il_ntimes,') ='&
00631 ,pl_io_info%p_cache%time_stamps(il_ntimes)
00632 call psmile_flushstd
00633 #endif
00634
00635
00636
00637
00638 do il_j=1,il_ndims
00639 call mpp_get_atts(pl_io_info%p_mpp_io%anaxis(il_j),name=cl_name &
00640 ,units=cl_uname)
00641 if(trim(cl_name).eq.'time' .or. &
00642 trim(cl_name).eq.'TIME' .or. &
00643 trim(cl_name).eq.'Time') exit
00644 enddo
00645
00646 if(il_j.gt.il_ndims) then
00647 ierror=PRISM_Error_IO_Open
00648 call psmile_error(ierror, &
00649 'The file '//trim(cl_filename)//' contains '// &
00650 ' non CF compliant identifier for time.', &
00651 ierrp,0, __FILE__, __LINE__)
00652 endif
00653
00654 call extract_date(cl_uname,ljobstart)
00655 #ifdef VERBOSE
00656 print*,trim(ch_id),' : PSMILe_open_file_byid:read: extracted date = ' &
00657 ,trim(cl_uname), ljobstart
00658 call psmile_flushstd
00659 #endif
00660 call psmile_date2ju(ljobstart,pl_io_info%ju_start_day &
00661 ,pl_io_info%ju_start_sec)
00662
00663
00664
00665
00666
00667
00668 Case (MPP_OVERWR)
00669
00670
00671
00672
00673 if(associated(Fields(id_varid)%io_infos%related_ids)) then
00674 fullsize=size(Fields(id_varid)%io_infos%related_ids)
00675 if(fullsize.gt.1) then
00676 do il_i=1,fullsize
00677 if(id_varid.eq. Fields(id_varid)%io_infos%related_ids(il_i)) exit
00678 enddo
00679 if(il_i.lt.fullsize) return
00680 endif
00681 endif
00682
00683
00684
00685
00686 il_filesize=2*pl_io_info%current_filesize-pl_io_info%old_filesize
00687
00688
00689
00690
00691
00692 if((il_filesize.le.0).and.(.not.pl_io_info%opened))then
00693
00694
00695
00696 call date_and_time(DATE=cl_date,TIME=cl_time,ZONE=cl_zone)
00697 cl_date='Date of creation: '//trim(cl_date)//' '//trim(cl_time) &
00698 //' '//trim(cl_zone)
00699
00700
00701
00702 If(len(trim(pl_io_info%filename)).eq.0) then
00703 pl_io_info%filename=trim( Fields(id_varid)%local_name)//'.nc'
00704 endif
00705
00706
00707
00708 if(pl_io_info%isuffix.eq.PSMILe_true) then
00709 il_initial_date(1)=current_date%year
00710 il_initial_date(2)=current_date%month
00711 il_initial_date(3)=current_date%day
00712 il_initial_date(4)=current_date%hour
00713 il_initial_date(5)=current_date%minute
00714 il_initial_date(6)=current_date%second
00715 call combine_with_date(pl_io_info%filename,'out' &
00716 ,il_initial_date,cl_filename)
00717 else
00718 cl_filename=trim(adjustl(pl_io_info%filename))
00719 endif
00720
00721 #ifdef VERBOSE
00722 print*,trim(ch_id),' : PSMILe_open_file_byid: mpp_open:write: ' &
00723 ,id_varid,pl_io_info%file_unit,trim(cl_filename),il_filesize
00724 call psmile_flushstd
00725 #endif
00726 call mpp_open(pl_io_info%file_unit,trim(cl_filename) &
00727 #ifdef __PARNETCDF
00728
00729 ,mpp_comm=IO_Apps_infos%comm &
00730 #endif
00731 ,action=pl_io_info%action &
00732 ,form=pl_io_info%format &
00733 ,threading=pl_io_info%threading &
00734 ,fileset=pl_io_info%fileset)
00735
00736 call mpp_write_meta(pl_io_info%file_unit &
00737 ,'Conventions' &
00738 ,cval='CF-1.0')
00739 call mpp_write_meta(pl_io_info%file_unit &
00740 ,'institution' &
00741 ,cval='PRISM')
00742 call mpp_write_meta(pl_io_info%file_unit &
00743 ,'source' &
00744 ,cval=trim(Comps(Fields(id_varid)%comp_id)%comp_name))
00745 call mpp_write_meta(pl_io_info%file_unit &
00746 ,'history' &
00747 ,cval=trim(cl_date))
00748 pl_io_info%opened=.true.
00749
00750
00751 else if(il_filesize.ge.PSMILE_IO_MAX_FILE_SIZE) then
00752
00753
00754
00755 call date_and_time(DATE=cl_date,TIME=cl_time,ZONE=cl_zone)
00756 cl_date='Date of creation: '//trim(cl_date)//' '//trim(cl_time) &
00757 //' '//trim(cl_zone)
00758
00759
00760
00761
00762 call psmile_close_file_byid(id_varid,id_taskid,ierror)
00763
00764 il_initial_date(1)=current_date%year
00765 il_initial_date(2)=current_date%month
00766 il_initial_date(3)=current_date%day
00767 il_initial_date(4)=current_date%hour
00768 il_initial_date(5)=current_date%minute
00769 il_initial_date(6)=current_date%second
00770 call combine_with_date(pl_io_info%filename, 'out' &
00771 ,il_initial_date,cl_filename)
00772 #ifdef VERBOSE
00773 print*,trim(ch_id),' : PSMILe_open_file_byid: mpp_open:reopen,write: ' &
00774 ,id_varid,pl_io_info%file_unit,trim(cl_filename),il_filesize
00775 call psmile_flushstd
00776 #endif
00777 call mpp_open(pl_io_info%file_unit,trim(cl_filename) &
00778 #ifdef __PARNETCDF
00779
00780 ,mpp_comm=IO_Apps_infos%comm &
00781 #endif
00782 ,action=pl_io_info%action &
00783 ,form=pl_io_info%format &
00784 ,threading=pl_io_info%threading &
00785 ,fileset=pl_io_info%fileset)
00786 call mpp_write_meta(pl_io_info%file_unit &
00787 ,'Conventions' &
00788 ,cval='CF-1.0')
00789 call mpp_write_meta(pl_io_info%file_unit &
00790 ,'institution' &
00791 ,cval='PRISM')
00792 call mpp_write_meta(pl_io_info%file_unit &
00793 ,'Source' &
00794 ,cval=trim(Comps(Fields(id_varid)%comp_id)%comp_name))
00795 call mpp_write_meta(pl_io_info%file_unit &
00796 ,'history' &
00797 ,cval=trim(cl_date))
00798
00799
00800
00801
00802 call psmile_write_meta_byid(id_varid,id_taskid,ierror)
00803
00804 pl_io_info%current_filesize=0
00805 pl_io_info%opened=.true.
00806
00807
00808 else
00809 #ifdef VERBOSE
00810 print*,trim(ch_id),' : PSMILe_open_file_byid: Estimated file size ' &
00811 ,'of ',trim(pl_io_info%filename) &
00812 ,'is ',il_filesize,' kB'
00813 call psmile_flushstd
00814 #endif
00815 endif
00816 Case DEFAULT
00817
00818 ierror=PRISM_Error_IO_Open
00819 ierrp(1)=pl_io_info%action
00820 ierrp(2)=MPP_RDONLY
00821 ierrp(3)=MPP_OVERWR
00822 call psmile_error(ierror,'Wrong action on file taken!', &
00823 ierrp,3, __FILE__, __LINE__)
00824
00825 End Select
00826 #ifdef VERBOSE
00827 print*,trim(ch_id),' : PSMILe_open_file_byid: end'
00828 call psmile_flushstd
00829 #endif
00830 #endif
00831
00832
00833 end subroutine PSMILe_open_file_byid