get_transi_io_numbers.F90

Go to the documentation of this file.
00001 !------------------------------------------------------------------------
00002 ! Copyright 2006-2010, CERFACS, Toulouse, France.
00003 ! All rights reserved. Use is subject to license terms.
00004 !------------------------------------------------------------------------
00005 !BOP
00006 !
00007 !======================================================================
00008 !
00009   SUBROUTINE get_transi_io_numbers ( id_XML_doc,  &
00010                                      id_nb_transi,       &
00011                                      ida_nb_stand_name,  &
00012                                      ida_nb_transi_in,   &
00013                                      ida_nb_transi_out,  &
00014                                      id_comp,            &
00015                                      cda_app_name,       &
00016                                      cda_comp_name,      &
00017                                      ld_first_details,   &
00018                                      id_error  )
00019 
00020 ! !DESCRIPTION
00021 ! This routine gives the number of input and output for each transi
00022 ! of one smioc
00023 !
00024 !----------------------------------------------------------------------
00025 !
00026     USE PSMILe_smioc
00027     IMPLICIT NONE
00028 !
00029 !EOP
00030 !----------------------------------------------------------------------
00031 ! $Id: psmile_smioc.F90 1793 2008-11-25 14:58:31Z valcke $
00032 ! $Author: valcke $
00033 !----------------------------------------------------------------------
00034 !
00035 ! 0. Declaration
00036 !
00037 ! handle of XML content of the smioc file
00038     INTEGER, INTENT(In) :: id_XML_doc
00039 
00040 ! number of transi variables for the component
00041     INTEGER, INTENT(In) :: id_nb_transi  
00042 
00043 ! number of standard name per transi for the component
00044     INTEGER, DIMENSION(id_nb_transi), INTENT(Out) :: ida_nb_stand_name
00045 
00046 ! number of input transi per transi for the component
00047     INTEGER, DIMENSION(id_nb_transi), INTENT(Out) :: ida_nb_transi_in
00048 
00049 ! number of output transi per transi for the component
00050     INTEGER, DIMENSION(id_nb_transi), INTENT(Out) :: ida_nb_transi_out
00051 
00052 ! Component id
00053     INTEGER, INTENT(In) :: id_comp
00054 
00055 ! Names of application and component
00056     CHARACTER(len=*), INTENT(In)  :: cda_app_name
00057     CHARACTER(len=*), INTENT(In)  :: cda_comp_name
00058 
00059 ! logical flag first pass / second pass
00060     LOGICAL, INTENT(In)  :: ld_first_details
00061 
00062 ! returned error code
00063    INTEGER, INTENT(Out) :: id_error 
00064 
00065 ! loop index
00066     INTEGER   :: ib,  ib_nt, ib_xml, ib_u
00067     INTEGER   :: il_xml_transi
00068 !
00069 #if CIM
00070   ! Name of all transients of the component
00071     Character(len=max_name), Allocatable :: cla_transient_name(:)
00072     INTEGER :: il_length
00073     
00074     ! Predicates for the search in XML path
00075     CHARACTER(len=282) :: cla_model_appli
00076     CHARACTER(len=282) :: cla_model_comp
00077     CHARACTER(len=282) :: cla_ref_comp
00078     
00079     ! total nb of, index of couplings
00080     INTEGER :: il_nb_couplings, il_coupling, il_test
00081     ! Index of connection
00082     INTEGER :: il_connection
00083     ! Name of the transient at one end of a connection
00084     Character(len=max_name) :: cl_connection_end
00085     
00086     !     ... for error handling
00087     INTEGER, PARAMETER  :: nerrp = 2
00088     INTEGER             :: ierrp (nerrp)
00089   
00090     INTEGER :: sasa_c_get_number_3rd_level, sasa_c_get_number_6th_level, sasa_c_get_number_8th_level
00091     INTEGER :: sasa_c_get_element_7th_level_c
00092 #else
00093     INTEGER :: sasa_c_get_number_3rd_level, sasa_c_get_number_4th_level
00094     INTEGER :: sasa_c_get_number_5th_level
00095 #endif!
00096 !----------------------------------------------------------------------
00097 !
00098 !  At first pass (called from prismdrv_get_udef_transients) :
00099 !  id_nb_transi = il_xml_transi = number of transients in XML SMIOC file
00100 !  At second pass (called from prismdrv_init_smioc_struct) :
00101 !  id_nb_transi = total number of transients including "udef" transients
00102     IF ( ld_first_details ) THEN
00103        il_xml_transi = id_nb_transi
00104     ELSE
00105        il_xml_transi = id_nb_transi - iga_comp_nb_udef(id_comp)
00106     ENDIF
00107 
00108 #if CIM
00109     ! Configuration data are in one CIM file
00110     ! --------------------------------------
00111 
00112     ! Allocate space for XML transient names
00113     ALLOCATE (cla_transient_name(il_xml_transi), stat=id_error )
00114     IF (id_error > 0) THEN
00115       ierrp (1) = id_error
00116       ierrp (2) = il_xml_transi
00117       id_error = 13
00118 
00119       CALL Psmile_Error_Common ( id_error, 'cla_transient_name', &
00120         ierrp, 2, __FILE__, __LINE__ )
00121       RETURN
00122     ENDIF
00123 
00124     ! Prepare two predicates for the search in the XML documents :
00125     !   based on application and model shortNames
00126     cla_model_appli = 'modelComponent[normalize-space(shortName)="'//TRIM(cda_app_name)//'"]'
00127     cla_model_comp  = 'modelComponent[normalize-space(shortName)="'//TRIM(cda_comp_name)//'"]'
00128 
00129     ! Get standard names for all component's transients
00130     
00131     ! For all the transients of the component
00132     DO ib =1, il_xml_transi
00133         ! Check if the transient is a bundle :
00134         !  if it, as a <componentProperty> element, has itself some <componentProperty> sub-elements
00135         id_error = &
00136             sasa_c_get_number_8th_level (id_XML_doc, &
00137             "simulationComposite/child/simulationRun/model/modelComponent", 0,            &
00138             "childComponent", 0, TRIM(cla_model_appli), 0, "childComponent", 0,           &
00139             TRIM(cla_model_comp), 0, "componentProperties", 0, "componentProperty", ib,   &
00140             "componentProperty", ida_nb_stand_name(ib))
00141             
00142         if (ida_nb_stand_name(ib) .eq. 0) then
00143             ! It should have at least one <standardName> sub-element
00144             id_error = &
00145                 sasa_c_get_number_8th_level (id_XML_doc, &
00146                 "simulationComposite/child/simulationRun/model/modelComponent", 0,            &
00147                 "childComponent", 0, TRIM(cla_model_appli), 0, "childComponent", 0,           &
00148                 TRIM(cla_model_comp), 0, "componentProperties", 0, "componentProperty", ib,   &
00149                 "standardName", ida_nb_stand_name(ib))
00150         else
00151             ! Transient is a bundle
00152             ! Add 1 to account for the main standard name
00153             ida_nb_stand_name(ib) = ida_nb_stand_name(ib) + 1
00154         endif
00155     ENDDO
00156     
00157     ! List all component's transient names
00158     
00159     ! For all component's transients
00160     DO ib =1, il_xml_transi
00161       cla_transient_name(ib) = ' '
00162       id_error = &
00163           sasa_c_get_element_7th_level_c (id_XML_doc, &
00164           "simulationComposite/child/simulationRun/model/modelComponent", 0,  &
00165           "childComponent", 0, TRIM(cla_model_appli), 0, "childComponent", 0, &
00166           TRIM(cla_model_comp), 0, "componentProperties", 0, "componentProperty", ib, &
00167           "shortName", 0, cla_transient_name(ib), il_length)
00168     ENDDO
00169 
00170     ! Get the number of couplings
00171     id_error = &
00172         sasa_c_get_number_3rd_level (id_XML_doc, &
00173         "simulationComposite/child/simulationRun/model/modelComponent", 0,     &
00174         "composition", 0, "coupling", il_nb_couplings)
00175 
00176     ! Count the number of connections involving any transient of this component
00177     ! -------------------------------------------------------------------------
00178     
00179     ida_nb_transi_in(:) = 0
00180     ida_nb_transi_out(:) = 0
00181     
00182     ! Prepare a predicate for the search of a <reference>-<name> element equal to component name
00183     cla_ref_comp = 'reference[normalize-space(name)="'//TRIM(cda_comp_name)//'"]'
00184     
00185     ! For all couplings
00186     DO il_coupling =1, il_nb_couplings
00187         ! Test if this coupling involves the component as the source
00188         id_error = &
00189             sasa_c_get_number_6th_level (id_XML_doc, &
00190             "simulationComposite/child/simulationRun/model/modelComponent", 0,   &
00191             "composition", 0, "coupling", il_coupling, "couplingSource", 0,      &
00192             "dataSource", 0, TRIM(cla_ref_comp), il_test)
00193             
00194         ! if this coupling involves the component as the source
00195         ! "il_test" is 0 or 1
00196         if (il_test > 0) then
00197         
00198             ! For all connections of that coupling
00199             il_connection = 1
00200             DO WHILE (.true.)
00201               ! Get name of connection source : it is a transient name
00202               cl_connection_end = ' '
00203               id_error = &
00204                   sasa_c_get_element_7th_level_c (id_XML_doc, &
00205                   "simulationComposite/child/simulationRun/model/modelComponent", 0,       &
00206                   "composition", 0, "coupling", il_coupling, "connection", il_connection,  &
00207                   "connectionSource", 0, "dataSource", 0, "reference", 0, "name", 0,       &
00208                   cl_connection_end, il_length)
00209 
00210               IF (il_length .ne. 0) then
00211                 ! Look for transient index based on its name
00212                 
00213                 ! For all component's transients
00214                 DO ib =1, il_xml_transi
00215                   IF (cl_connection_end .eq. cla_transient_name(ib)) then
00216                     ! Increment number of connections involving this transient as a source
00217                     ida_nb_transi_out(ib) = ida_nb_transi_out(ib) + 1
00218                     exit
00219                   ENDIF
00220                 ENDDO
00221                 
00222                 ! Go to next connection
00223                 il_connection = il_connection + 1
00224               
00225               ELSE
00226                 ! No more connections in this coupling
00227                 exit
00228               ENDIF
00229             ENDDO
00230         endif
00231     
00232         ! Test if this coupling involves the component as the target
00233         id_error = &
00234             sasa_c_get_number_6th_level (id_XML_doc, &
00235             "simulationComposite/child/simulationRun/model/modelComponent", 0,   &
00236             "composition", 0, "coupling", il_coupling, "couplingTarget", 0,      &
00237             "dataSource", 0, TRIM(cla_ref_comp), il_test)
00238             
00239         ! if this coupling involves the component as the target
00240         ! "il_test" is 0 or 1
00241         if (il_test > 0) then
00242         
00243             ! For all connections of that coupling
00244             il_connection = 1
00245             DO WHILE (.true.)
00246               ! Get name of connection target : it is a transient name
00247               cl_connection_end = ' '
00248               id_error = &
00249                   sasa_c_get_element_7th_level_c (id_XML_doc, &
00250                   "simulationComposite/child/simulationRun/model/modelComponent", 0,       &
00251                   "composition", 0, "coupling", il_coupling, "connection", il_connection,  &
00252                   "connectionTarget", 0, "dataSource", 0, "reference", 0, "name", 0,       &
00253                   cl_connection_end, il_length)
00254 
00255               IF (il_length .ne. 0) then
00256                 ! Look for transient index based on its name
00257                 
00258                 ! For all component's transients
00259                 DO ib =1, il_xml_transi
00260                   IF (cl_connection_end .eq. cla_transient_name(ib)) then
00261                     ! Increment number of connections involving this transient as a target
00262                     ida_nb_transi_in(ib) = ida_nb_transi_in(ib) + 1
00263                     exit
00264                   ENDIF
00265                 ENDDO
00266                 
00267                 ! Go to next connection
00268                 il_connection = il_connection + 1
00269               
00270               ELSE
00271                 ! No more connections in this coupling
00272                 exit
00273               ENDIF
00274             ENDDO
00275         endif
00276     
00277     ENDDO
00278     
00279 #ifdef DEBUG
00280     print *, "component name: ", cda_comp_name
00281     print *, "ida_nb_transi_in : ", ida_nb_transi_in(:)
00282     print *, "ida_nb_transi_out : ", ida_nb_transi_out(:)
00283 #endif
00284     
00285     DEALLOCATE (cla_transient_name)
00286 #else
00287     ! Configuration data are in a SMIOC file
00288     ! --------------------------------------
00289 
00290 ! For all the transients of the component
00291     DO ib =1, il_xml_transi
00292          id_error = &
00293          sasa_c_get_number_3rd_level(id_XML_doc,                             &
00294          'component', 0, 'transient', ib, 'transient_standard_name',    &
00295          ida_nb_stand_name(ib))
00296          print *,' get_transi_io_numbers id_error stand_name ib = ',ib, id_error
00297 
00298       id_error = &
00299          sasa_c_get_number_5th_level(id_XML_doc,              &
00300          'component', 0, 'transient', ib, 'intent', 0,   &
00301          'input', 0, 'origin', ida_nb_transi_in(ib))
00302          print *,' get_transi_io_numbers id_error transi_in ib = ',ib, id_error
00303 
00304       id_error = &
00305          sasa_c_get_number_4th_level(id_XML_doc,              &
00306          'component', 0, 'transient', ib, 'intent', 0,   &
00307          'output', ida_nb_transi_out(ib))
00308          print *,' get_transi_io_numbers id_error transi_out ib = ',ib, id_error
00309     END DO
00310 #endif
00311 
00312 !  At second pass (called from prismdrv_init_smioc_struct) :
00313 !  we add indexes for userdef transients
00314 !  It is supposed that the number of standard names are the same
00315 !  in the associated "udef" transient
00316 !  These numbers are copied from the geographical transient
00317 !  In associated "gridless" transients, Number of origins = 1
00318 !  and number of outputs = 1
00319 
00320     IF ( .NOT. ld_first_details ) THEN
00321 !  "Udef" transients    
00322        ib_nt = 0
00323        DO ib_u = il_xml_transi + 1, id_nb_transi
00324           ib_nt = ib_nt + 1
00325 !  ib_xml is the transient index in component XML SMIOC file
00326           ib_xml = sga_comp_udef_idx(id_comp)%iga_xml_trindex(ib_nt)
00327 !  Number of standard names is the same in all associated "gridless" transients
00328           ida_nb_stand_name(ib_u) = ida_nb_stand_name(ib_xml)        
00329 !  Number of origins is always 1 or 0 in gridless transients
00330           IF ( ida_nb_transi_in(ib_xml) .NE. 0 ) THEN 
00331              ida_nb_transi_in(ib_u) = 1
00332           ELSE
00333              ida_nb_transi_in(ib_u) = 0
00334           ENDIF
00335 !  Number of outputs is always 1 or 0 in gridless transients
00336           IF ( ida_nb_transi_out(ib_xml) .NE. 0 ) THEN
00337              ida_nb_transi_out(ib_u) = 1
00338           ELSE
00339              ida_nb_transi_out(ib_u) = 0
00340           ENDIF 
00341        ENDDO
00342 
00343     ENDIF
00344 
00345   END SUBROUTINE get_transi_io_numbers
00346 
00347 !
00348 !======================================================================

Generated on 1 Dec 2011 for Oasis4 by  doxygen 1.6.1