Access to Optional Arguments which are Not Present

| SimCon Home | fpt Reference Manual Home |

Optional Arguments and IF (PRESENT(...))

If an optional argument is accessed during a sub-program call in which it is not present, an error is likely to occur. Access to optional arguments may be guarded by IF (PRESENT( <argument> )) constructs.

What Happens if an Access is Made when the Argument is Not Present?

The possibilities are (At least):

Testing for IF (PRESENT(...))

The fpt command to test whether optional arguments are guarded is:


fpt finds each executable statement which contains an optional argument and traces program flow backwards towards the entry to the routine in which it occurs. If there is a path to the start of the routine, the occurrence is marked as a potential unguarded reference.

Why Only a Potential Unguarded Reference?

For at least two reasons:

The end of the report, including a summary of the number of occurrences, is shown below for WRFV3.6.1.

------------------------------------------------------------------------------ !!! WARNING !!! Number 3637 Severity 1 (Worst 2) Count 12175 Line 1655 File: ...cation/test/UCAR_clean_build_WRFV3.6.1/WRFV3/phys/module_pbl_driver.F ,z = z,t_phy = t_phy,qc_curr = qc_curr,qi_curr = qi_curr,z_at_w = z_at_w & ^ Unguarded use of an OPTIONAL argument which is always PRESENT ------------------------------------------------------------------------------ ------------------------------------------------------------------------------ !!! WARNING !!! Number 3637 Severity 1 (Worst 2) Count 12176 Line 1664 File: #if ( WRF_CHEM == 1 ) qv_b4mp(its:ite,kts:kte,jts:jte) = qv_curr(its:ite,kts:kte,jts:jte) qc_b4mp(its:ite,kts:kte,jts:jte) = qc_curr(its:ite,kts:kte,jts:jte) qi_b4mp(its:ite,kts:kte,jts:jte) = qi_curr(its:ite,kts:kte,jts:jte) qs_b4mp(its:ite,kts:kte,jts:jte) = qs_curr(its:ite,kts:kte,jts:jte) #endif ,t_phy = t_phy,pi_phy = pi_phy,z_at_w = z_at_w,qfx = qfx & ^ Unguarded use of an OPTIONAL argument which is always PRESENT ------------------------------------------------------------------------------ Check for unguarded access to OPTIONAL arguments ================================================ Optional arguments: 3194 Not always present and with unguarded references (Errors): 35 Always present but with unguarded references (Warnings): 1325 Arguments with possible unguarded references (Warnings): 1 Total number of unguarded references: 2529

A run-time check for unguarded references

The fpt command:


inserts a check for presence before every access to an optional argument where no guard has already been identified. Within the check, a call is inserted to a subroutine which counts the number of visits to this location. The count is held in an array indexed by a unique integer identifier for each call.

A section of the instrumented code from WRFV3.6.1 is shown below:

Target found at line: 438 in file: .../UCAR_clean_build_WRFV3.6.1/WRFV3/phys/module_lightning_driver.F CALL wrf_debug(100,' lightning_driver: using option-default IC:CG method') ICCG_METHOD_DEFAULT:SELECT CASE(lightning_option) ! CASE(ltng_crm_pr92w,ltng_crm_pr92z,ltng_cpm_pr92z)ICCG_METHOD_DEFAULT IF (.NOT. PRESENT(cg_flashrate)) THEN CALL fpt_check_present(386) ENDIF IF (.NOT. PRESENT(ic_flashrate)) THEN CALL fpt_check_present(909) ENDIF CALL iccg_boccippio( & xlat,xlon, & iccg_prescribed_num,iccg_prescribed_den, & ! Order dependent args for domain, mem, and tile dims ids,ide,jds,jde,kds,kde, & ims,ime,jms,jme,kms,kme, &

Copyright ©1995 to 2017 Software Validation Ltd. All rights reserved.