go_system.F90 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  1. !###############################################################################
  2. !
  3. ! NAME
  4. ! GO_System - machine and/or compiler specific stuff
  5. !
  6. !
  7. ! DESCRIPTION
  8. !
  9. ! The module GO_System provides some basic constants for the
  10. ! current compiler. In addition, some interfaces are defined
  11. ! to routines for system calls, setting of exit statuses etc,
  12. ! which are non-standard Fortran, but often provided by the
  13. ! vendor of the compiler.
  14. ! Since both constants and system routines differ from compiler
  15. ! to compiler, this GO module is available in a number of copies,
  16. ! each valid for a single compiler. If for some compiler a
  17. ! certain constant or system routine could not be filled,
  18. ! a dummy value is used or a warning is issued.
  19. !
  20. ! The following system routines are defined:
  21. !
  22. ! o call goSystem( command, status )
  23. ! Perform a system command, return exit status.
  24. !
  25. ! o call goExit( status )
  26. ! Stop execution, set the exit status.
  27. !
  28. ! o call goArgCount( narg, status )
  29. ! Count number of command line arguments.
  30. !
  31. ! o call goGetArg( nr, value, status )
  32. ! Returns command line argument 'nr' in character string 'value'.
  33. !
  34. ! o call goSleep( nsec, status )
  35. ! Wait for some seconds.
  36. !
  37. !
  38. ! GFORTRAN
  39. !
  40. ! Online manual:
  41. !
  42. ! gcc.gnu.org/onlinedocs/
  43. ! (choose version)
  44. !
  45. ! Macro's defined from version 4.3.5 onwards
  46. ! (section "Preprocessing and conditional compilation" in the manual):
  47. !
  48. ! __GFORTRAN__
  49. ! __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__
  50. !
  51. ! According to the manual, this should work to list all defined macro's,
  52. ! but when tested it only seemd to work with gcc:
  53. !
  54. ! gfortran -dM test.F90
  55. !
  56. !
  57. ! INTEL FORTRAN COMPILER
  58. !
  59. ! Online manual:
  60. !
  61. ! www.intel.com
  62. ! Sitemap, Software, Find Product : Intel Compilers
  63. ! Select 'Product Documentation' from the side menu
  64. ! Intel Fortran Compiler 11.1 User and Reference Guides
  65. ! (http://software.intel.com/sites/products/documentation/hpc/compilerpro/en-us/fortran/lin/compiler_f/index.htm)
  66. ! Language Reference
  67. !
  68. ! Macro's defined:
  69. !
  70. ! __INTEL_COMPILER ! evaluates to version number
  71. !
  72. !
  73. ! IBM XLF COMPILER
  74. !
  75. ! Online manuals are there but hard to locate; therefore some hints:
  76. !
  77. ! Language Reference - XL Fortran for AIX, V12.1
  78. ! Service and utility procedures
  79. ! General service and utility procedures
  80. !
  81. ! For the macro definitions, see:
  82. !
  83. ! XL C/C++ Compiler Reference Version 10.1
  84. ! Compiler Predefined Macros
  85. ! Macros indicating the XL C/C++ compiler product
  86. !
  87. ! Use '__IBMC__' rather than __xlc__ since the first evaluates
  88. ! to a single integer number which can be tested with:
  89. ! #if __IBMC__ == 1010
  90. ! while the later evaluates to string like '10.1.0.4' .
  91. !
  92. ! Compilation on ECMWF systems fails during linking because 'Exit_'
  93. ! and 'Sleep_' could not be found. Although these are the standard names
  94. ! according to the Compiler Reference, the ECMWF implementation only
  95. ! recoqnizes 'Exit' and 'Sleep' (thus without underscores).
  96. ! Adding the flag '-qnoextname' solves this, but induces a failure in
  97. ! linking the HDF4 library. Therefore, a macro '__ecmwf__' should be
  98. ! defined to distuinguish between XLF implementations at ECMWF and
  99. ! at other institutes.
  100. !
  101. !
  102. !###############################################################################
  103. !
  104. #define TRACEBACK write (gol,'("in ",a," (line",i5,")")') __FILE__, __LINE__; call goErr
  105. #define IF_NOTOK_RETURN(action) if (status/=0) then; TRACEBACK; action; return; end if
  106. #define IF_ERROR_RETURN(action) if (status >0) then; TRACEBACK; action; return; end if
  107. !
  108. !###############################################################################
  109. module GO_System
  110. use GO_Print, only : gol, goPr, goErr
  111. implicit none
  112. ! --- in/out ------------------------------
  113. private
  114. public :: goSystem
  115. public :: goExit
  116. public :: goArgCount, goGetArg
  117. public :: goSleep
  118. public :: pathsep
  119. ! --- const ---------------------------------
  120. ! module name
  121. character(len=*), parameter :: mname = 'GO_System'
  122. ! path seperation:
  123. character(len=1), parameter :: pathsep = '/'
  124. contains
  125. ! ############################################################################
  126. ! ###
  127. ! ### goSystem
  128. ! ###
  129. ! ############################################################################
  130. ! Execute a system command, return exit status.
  131. subroutine goSystem( command, status )
  132. #ifdef __INTEL_COMPILER
  133. use IFPort, only : System
  134. use IFPort, only : iErrNo, E2BIG, ENOENT, ENOEXEC, ENOMEM
  135. #endif
  136. ! --- in/out -----------------------------------------------
  137. character(len=*), intent(in) :: command
  138. integer, intent(inout) :: status
  139. ! --- const ------------------------------------------------
  140. character(len=*), parameter :: rname = mname//'/goSystem'
  141. ! --- local --------------------------------------------------
  142. #ifdef __INTEL_COMPILER
  143. integer(4) :: stat
  144. integer(4) :: errno
  145. #endif
  146. ! --- begin --------------------------------------------------
  147. #ifdef __INTEL_COMPILER
  148. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  149. ! Intel Compiler
  150. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  151. !
  152. ! From manual:
  153. !
  154. ! Intel Fortran Compiler 11.1 User and Reference Guides
  155. ! Language Reference
  156. ! A to Z Reference
  157. ! System
  158. !
  159. stat = System( command )
  160. ! trap errors in ifort system command
  161. if ( stat == -1 ) then
  162. write (gol,'("error in call to IFort Portability command `system`:")'); call goErr
  163. errno = iErrNo()
  164. select case ( errno )
  165. case ( E2BIG )
  166. write (gol,'(" ",a)') 'The argument list is too long.'; call goErr
  167. case ( ENOENT )
  168. write (gol,'(" ",a)') 'The command interpreter cannot be found.'; call goErr
  169. case ( ENOEXEC )
  170. write (gol,'(" ",a)') 'The command interpreter file has an invalid format and is not executable.'; call goErr
  171. case ( ENOMEM )
  172. write (gol,'(" ",a)') 'Not enough system resources are available to execute the command.'; call goErr
  173. case default
  174. write (gol,'(" unknown iErrNo ",i)') errno; call goErr
  175. end select
  176. TRACEBACK; status=stat; return
  177. end if
  178. ! if the shell command exit status is 'n',
  179. ! then the number returned by 'system' is 256 * n
  180. status = stat / 256
  181. #else
  182. #ifdef __GFORTRAN__
  183. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  184. ! GNU Fortran Compiler
  185. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  186. !
  187. ! From manual:
  188. !
  189. ! gcc.gnu.org/onlinedocs/
  190. ! GCC 4.3.5 GNU Fortran 95 Manual
  191. ! 6. Intrinsic Prodedures
  192. ! 204. SYSTEM - Execute a shell command
  193. !
  194. call System( command, status )
  195. #else
  196. #ifdef __IBMC__
  197. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  198. ! IBM XL Fortran Compiler
  199. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  200. !
  201. ! From manual:
  202. !
  203. ! Language Reference - XL Fortran for AIX, V12.1
  204. ! Intrinsic Procedures
  205. !
  206. call System( command, status )
  207. #else
  208. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  209. ! error ...
  210. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  211. !write (gol,'("could not evaluate system command : ",a)') trim(command); call goErr
  212. !write (gol,'("subroutine not implemented for this compiler")'); call goErr
  213. !TRACEBACK; status=1; return
  214. ! try this, often works:
  215. call System( command, status )
  216. #endif
  217. #endif
  218. #endif
  219. end subroutine goSystem
  220. ! ############################################################################
  221. ! ###
  222. ! ### goExit
  223. ! ###
  224. ! ############################################################################
  225. ! Stop execution, set exit status.
  226. subroutine goExit( status )
  227. #ifdef __IBMC__
  228. use XLFUtility, only : Exit_
  229. #endif
  230. ! --- in/out --------------------------------------------
  231. integer, intent(in) :: status
  232. ! --- const ------------------------------------------------
  233. character(len=*), parameter :: rname = mname//'/goExit'
  234. ! --- begin --------------------------------------------
  235. #ifdef __INTEL_COMPILER
  236. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  237. ! Intel compiler
  238. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  239. !
  240. ! From manual:
  241. !
  242. ! Intel Fortran Compiler 11.1 User and Reference Guides
  243. ! Language Reference
  244. ! A to Z Reference
  245. ! Exit Subroutine
  246. !
  247. call Exit( status )
  248. #else
  249. #ifdef __GFORTRAN__
  250. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  251. ! GNU Fortran compiler
  252. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  253. !
  254. ! From manual:
  255. !
  256. ! gcc.gnu.org/onlinedocs/
  257. ! GCC 4.3.5 GNU Fortran 95 Manual
  258. ! 6. Intrinsic Prodedures
  259. ! 6.66. EXIT - Exit the program with status.
  260. !
  261. call Exit( status )
  262. #else
  263. #ifdef __IBMC__
  264. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  265. ! IBM XLF compiler
  266. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  267. !
  268. ! From manual:
  269. !
  270. ! Language Reference - XL Fortran for AIX, V12.1
  271. ! Service and utility procedures
  272. ! General service and utility procedures
  273. !
  274. #ifdef __ecmwf__
  275. call Exit( status )
  276. #else
  277. call Exit_( status )
  278. #endif
  279. #else
  280. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  281. ! error ...
  282. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  283. !write (gol,'("subroutine not implemented for this compiler")'); call goErr
  284. !! this is an emergency, so for one time, the Fortran stop is allowed ...
  285. !stop 'Fortran STOP in GO_System/goExit'
  286. ! try this, often works:
  287. call Exit( status )
  288. #endif
  289. #endif
  290. #endif
  291. end subroutine goExit
  292. ! ############################################################################
  293. ! ###
  294. ! ### goArgCount
  295. ! ###
  296. ! ############################################################################
  297. ! Return number of command line arguments
  298. subroutine goArgCount( narg, status )
  299. ! --- in/out --------------------------------------------
  300. integer, intent(out) :: narg
  301. integer, intent(out) :: status
  302. ! --- const ------------------------------------------------
  303. character(len=*), parameter :: rname = mname//'/goArgCount'
  304. !***ABUTZ:2012-04-12@imkpcabu
  305. integer :: iargc
  306. ! --- begin -------------------------------------------------
  307. #ifdef __INTEL_COMPILER
  308. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  309. ! Intel Compiler
  310. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  311. !
  312. ! From manual:
  313. !
  314. ! Intel Fortran Compiler 11.1 User and Reference Guides
  315. ! Language Reference
  316. ! A to Z Reference
  317. ! Command_Argument_Count
  318. !
  319. narg = Command_Argument_Count()
  320. #else
  321. #ifdef __GFORTRAN__
  322. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  323. ! GNU Fortran Compiler
  324. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  325. !
  326. ! From manual:
  327. !
  328. ! gcc.gnu.org/onlinedocs/
  329. ! GCC 4.3.5 GNU Fortran 95 Manual
  330. ! 6. Intrinsic Prodedures
  331. ! 6.42. COMMAND_ARGUMENT_COUNT - Get number of command line arguments
  332. !
  333. narg = Command_Argument_Count()
  334. #else
  335. #ifdef __IBMC__
  336. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  337. ! IBM XLF compiler
  338. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  339. !
  340. ! From manual:
  341. !
  342. ! Language Reference - XL Fortran for AIX, V12.1
  343. ! Intrinsic Procedures
  344. !
  345. narg = Command_Argument_Count()
  346. #else
  347. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  348. ! error ...
  349. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  350. !! always assign something ...
  351. !narg = -1
  352. !write (gol,'("subroutine not implemented for this compiler")'); call goErr
  353. !TRACEBACK; status=1; return
  354. ! try this, often works:
  355. narg = iArgC()
  356. #endif
  357. #endif
  358. #endif
  359. ! ok
  360. status = 0
  361. end subroutine goArgCount
  362. ! ############################################################################
  363. ! ###
  364. ! ### goGetArg
  365. ! ###
  366. ! ############################################################################
  367. ! Return a command line argument
  368. subroutine goGetArg( pos, value, status )
  369. ! --- in/out --------------------------------------------------
  370. integer, intent(in) :: pos
  371. character(len=*), intent(out) :: value
  372. integer, intent(inout) :: status
  373. ! --- const ------------------------------------------------
  374. character(len=*), parameter :: rname = mname//'/goGetArg'
  375. ! --- local -----------------------------------------------------
  376. integer :: n
  377. ! --- begin -----------------------------------------------------
  378. #ifdef __INTEL_COMPILER
  379. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  380. ! Intel Compiler
  381. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  382. !
  383. ! From manual:
  384. !
  385. ! Intel Fortran Compiler 11.1 User and Reference Guides
  386. ! Language Reference
  387. ! A to Z Reference
  388. ! Get_Command_Argument
  389. !
  390. ! Following the F2003 standard:
  391. call Get_Command_Argument( pos, value=value, status=status )
  392. #else
  393. #ifdef __GFORTRAN__
  394. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  395. ! GNU Fortran Compiler
  396. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  397. !
  398. ! From manual:
  399. !
  400. ! gcc.gnu.org/onlinedocs/
  401. !
  402. ! GCC 4.3.5 GNU Fortran 95 Manual
  403. ! 6. Intrinsic Prodedures
  404. ! 6.87. GET_COMMAND_ARGUMENT - Get command line arguments
  405. ! call Get_Command_Argument( pos, value )
  406. !
  407. ! GCC 4.4.4 GNU Fortran 95 Manual
  408. ! 7. Intrinsic Prodedures
  409. ! 7.89. GET_COMMAND_ARGUMENT - Get command line arguments
  410. ! call Get_Command_Argument( pos [,value, length, status] )
  411. !
  412. #ifdef __GNUC____GNUC_MINOR____GNUC_PATCHLEVEL__ == 435
  413. ! up to version 4.3.5 :
  414. call Get_Command_Argument( pos, value )
  415. ! no status returned ...
  416. status = 0
  417. #else
  418. ! Following the F2003 standard from v4.4.4 onwards:
  419. call Get_Command_Argument( pos, value=value, status=status )
  420. #endif
  421. #else
  422. #ifdef __IBMC__
  423. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  424. ! IBM XLF compiler
  425. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  426. !
  427. ! From manual:
  428. !
  429. ! Language Reference - XL Fortran for AIX, V12.1
  430. ! Intrinsic Procedures
  431. !
  432. ! Following the F2003 standard:
  433. call Get_Command_Argument( pos, value=value, status=status )
  434. #else
  435. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  436. ! error ...
  437. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  438. !! use arguments to avoid compilation warnings:
  439. !status = pos
  440. !! always assign something ...
  441. !value = '?'
  442. !write (gol,'("subroutine not implemented for this compiler")'); call goErr
  443. !TRACEBACK; status=1; return
  444. ! try this, often works:
  445. call GetArg( pos, value )
  446. ! no status returned ...
  447. status = 0
  448. #endif
  449. #endif
  450. #endif
  451. end subroutine goGetArg
  452. ! ############################################################################
  453. ! ###
  454. ! ### goSleep
  455. ! ###
  456. ! ############################################################################
  457. ! wait some seconds ...
  458. subroutine goSleep( nsec, status )
  459. #ifdef __INTEL_COMPILER
  460. use IFPort, only : Sleep
  461. #endif
  462. #ifdef __IBMC__
  463. use XLFUtility, only : Sleep_
  464. #endif
  465. ! --- in/out --------------------------------------------------
  466. integer, intent(in) :: nsec
  467. integer, intent(out) :: status
  468. ! --- const ------------------------------------------------
  469. character(len=*), parameter :: rname = mname//'/goSleep'
  470. ! --- begin -----------------------------------------------------
  471. #ifdef __INTEL_COMPILER
  472. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  473. ! Intel Compiler
  474. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  475. !
  476. ! From manual:
  477. !
  478. ! Intel Fortran Compiler 11.1 User and Reference Guides
  479. ! Language Reference
  480. ! A to Z Reference
  481. ! Sleep
  482. !
  483. call Sleep( nsec )
  484. #else
  485. #ifdef __GFORTRAN__
  486. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  487. ! GNU Fortran Compiler
  488. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  489. !
  490. ! From manual:
  491. !
  492. ! gcc.gnu.org/onlinedocs/
  493. ! GCC 4.3.5 GNU Fortran 95 Manual
  494. ! 6. Intrinsic Prodedures
  495. ! 6.195. SLEEP - Sleep for the specified number of seconds
  496. !
  497. call Sleep( nsec )
  498. #else
  499. #ifdef __IBMC__
  500. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  501. ! IBM XLF compiler
  502. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  503. !
  504. ! From manual:
  505. !
  506. ! Language Reference - XL Fortran for AIX, V12.1
  507. ! Service and utility procedures
  508. ! General service and utility procedures
  509. !
  510. #ifdef __ecmwf__
  511. call Sleep( nsec )
  512. #else
  513. call Sleep_( nsec )
  514. #endif
  515. #else
  516. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  517. ! error ...
  518. ! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  519. !write (gol,'("subroutine not implemented for this compiler")'); call goErr
  520. !TRACEBACK; status=1; return
  521. ! try this, often works:
  522. call Sleep( nsec )
  523. #endif
  524. #endif
  525. #endif
  526. ! ok
  527. status = 0
  528. end subroutine goSleep
  529. end module GO_System
  530. !! ######################################################################
  531. !! ###
  532. !! ### test
  533. !! ###
  534. !! ######################################################################
  535. !!
  536. !! gfortran -o test.x go_fu.F90 go_print.F90 go_system.F90 && ./test.x a bc ; echo $?
  537. !!
  538. !! ifort -o test.x go_fu.F90 go_print.F90 go_system.F90 && ./test.x a bc ; echo $?
  539. !!
  540. !! xlf -qnoextname -o test.x go_fu.F90 go_print.F90 go_system.F90 && ./test.x a bc ; echo $?
  541. !!
  542. !! xlf -qnoextname -o test.x -WF,-D__ecmwf__ go_fu.F90 go_print.F90 go_system.F90 && ./test.x a bc ; echo $?
  543. !!
  544. !#define IF_NOTOK_STOP if (status/=0) then; TRACEBACK; stop; end if
  545. !!
  546. !program test
  547. !
  548. ! use GO_Print, only : gol, goPr, goErr
  549. ! use GO_System, only : goArgCount, goGetArg, goExit, goSleep, goSystem
  550. !
  551. ! implicit none
  552. !
  553. ! character(len=*), parameter :: rname = 'test'
  554. !
  555. ! integer :: status
  556. ! integer :: n, i
  557. ! character(len=32) :: val
  558. ! character(len=32) :: command
  559. !
  560. ! print *, 'begin'
  561. !
  562. ! print *, ''
  563. ! print *, 'Test value of predefined macros:'
  564. !#ifdef __GFORTRAN__
  565. ! print *, ' __GFORTRAN__ : ', __GFORTRAN__
  566. ! print *, ' __GNUC__ : ', __GNUC__
  567. ! print *, ' __GNUC_MINOR__ : ', __GNUC_MINOR__
  568. ! print *, ' __GNUC_PATCHLEVEL__ : ', __GNUC_PATCHLEVEL__
  569. !#else
  570. ! print *, ' __GFORTRAN__ : undefined'
  571. !#endif
  572. !#ifdef __INTEL_COMPILER
  573. ! print *, ' __INTEL_COMPILER : ', __INTEL_COMPILER
  574. !#else
  575. ! print *, ' __INTEL_COMPILER : undefined'
  576. !#endif
  577. !#ifdef __IBMC__
  578. ! print *, ' __IBMC__ : ', __IBMC__
  579. !#else
  580. ! print *, ' __IBMC__ : undefined'
  581. !#endif
  582. !
  583. ! print *, ''
  584. ! print *, 'number of arguments ...'
  585. ! call goArgCount( n, status )
  586. ! IF_NOTOK_STOP
  587. ! print *, n
  588. !
  589. ! print *, 'get arguments ...'
  590. ! do i = 1, n
  591. ! print *, ' argument ', i, ' ...'
  592. ! call goGetArg( i, val, status )
  593. ! IF_NOTOK_STOP
  594. ! print *, '"'//trim(val)//'"'
  595. ! end do
  596. !
  597. ! command = '/bin/ls -l'
  598. ! print *, ''
  599. ! print *, 'call system command : ', trim(command)
  600. ! call goSystem( command, status )
  601. ! IF_NOTOK_STOP
  602. !
  603. ! n = 2
  604. ! print *, ''
  605. ! print *, 'wait ', n, ' seconds ...'
  606. ! call goSleep( n, status )
  607. ! IF_NOTOK_STOP
  608. !
  609. ! status = 23
  610. ! print *, ''
  611. ! print *, 'exit with status ', status, ' ...'
  612. ! call goExit( status )
  613. !
  614. ! print *, 'end'
  615. !
  616. !end program test