f_udunits_2.f90 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149
  1. module f_udunits_2
  2. ! FORTRAN interface to the C library udunits2 (C) Copyright UCAR/Unidata
  3. ! Michel Valin
  4. ! Université du Québec à Montréal
  5. ! August 2012
  6. !
  7. ! a version of the FORTRAN compiler that supports
  8. ! use ISO_C_BINDING
  9. ! is needed (development/testing done with gfortran 4.6)
  10. ! recent versions of the Portland group / Intel / IBM xlf compilers
  11. ! should also work (testing to be done soon)
  12. !
  13. ! for all the C functions that have been interfaced:
  14. !
  15. ! 0- the calling FORTRAN code must include
  16. ! use f_udunits_2
  17. ! to use these FORTRAN functions/subroutines
  18. !
  19. ! 1- the FORTRAN name will be the C name prefixed with f_
  20. ! FORTRAN function f_ut_read_xml mimics C function ut_read_xml
  21. !
  22. ! 2- where the C code uses a typed pointer, the FORTRAN code uses a typed object
  23. !
  24. ! type(UT_SYSTEM_PTR) replaces ut_system*
  25. ! type(UT_UNIT_PTR) replaces ut_unit*
  26. ! type(CV_CONVERTER_PTR) replaces cv_converter*
  27. !
  28. ! 3- where a C function has a void return, a FORTRAN subroutine is used
  29. !
  30. ! 4- where a C function returns zero/nonzero for a C style true/false
  31. ! the equivalent FORTRAN function returns a FORTRAN logical
  32. ! (to be usable in an equivalent way in a logical expression)
  33. !
  34. ! 5a- where a C input argument is char *, the FORTRAN code uses character(len=*)
  35. ! copy to a C compatible zero terminated string is handled internally
  36. ! the FORTRAN string is "trailing blanks trimmed" before the zero byte is added
  37. !
  38. ! 5b- where a C function returns char *, the FORTRAN function return type is character(len=256)
  39. !
  40. ! 6- ut_status is an integer, symbols with the same name are available to FORTRAN with
  41. ! use f_udunits_2
  42. !
  43. ! 7- ut_encoding is an integer, symbols with the same name are available to FORTRAN with
  44. ! use f_udunits_2
  45. !
  46. ! NOTES:
  47. !
  48. ! documentation for the C code :
  49. ! http://www.unidata.ucar.edu/software/udunits/udunits-2.0.4/udunits2lib.html
  50. !
  51. ! FORTRAN interface for function returning char * (ut_trim) not implemented
  52. ! one should use FORTRAN trim function (may not work in all cases)
  53. !
  54. ! FORTRAN interfaces to "visitor" functions are not implemented
  55. ! ut_accept_visitor (const ut_unit* unit, const ut_visitor* visitor, void* arg)
  56. ! Data type: ut_visitor
  57. !
  58. ! FORTRAN interfaces to functions using a variable argument list and message handler
  59. ! are not implemented
  60. ! int ut_handle_error_message (const char* fmt, ...)
  61. ! ut_error_message_handler ut_set_error_message_handler (ut_error_message_handler handler)
  62. ! int ut_write_to_stderr (const char* fmt, va_list args)
  63. ! int ut_ignore (const char* fmt, va_list args)
  64. ! int ut_ignore (const char* fmt, va_list args)
  65. ! typedef int (*ut_error_message_handler)(const char* fmt, va_list args);
  66. !
  67. use ISO_C_BINDING
  68. implicit none
  69. include 'f_udunits_2.inc'
  70. ! PLS
  71. interface f_cv_convert
  72. module procedure f_cv_convert_float
  73. module procedure f_cv_convert_double
  74. end interface
  75. ! interface f_cv_convert_more
  76. ! module procedure f_cv_convert_floats
  77. ! module procedure f_cv_convert_doubles
  78. ! end interface
  79. contains
  80. !=============================================================================
  81. type(UT_SYSTEM_PTR) function f_ut_read_xml(path)
  82. use ISO_C_BINDING
  83. implicit none
  84. character (len=*), intent(IN) :: path
  85. character (len=1), dimension(len_trim(path)+1), target :: temp
  86. interface
  87. type(C_PTR) function c_ut_read_xml(mypath) bind(C,name='ut_read_xml')
  88. use ISO_C_BINDING
  89. implicit none
  90. type(C_PTR), value :: mypath
  91. end function c_ut_read_xml
  92. end interface
  93. if(path == "" )then
  94. f_ut_read_xml%ptr = c_ut_read_xml(C_NULL_PTR)
  95. else
  96. temp = transfer( trim(path)//achar(0) , temp )
  97. f_ut_read_xml%ptr = c_ut_read_xml(c_loc(temp))
  98. endif
  99. return
  100. end function f_ut_read_xml
  101. !=============================================================================
  102. type(UT_SYSTEM_PTR) function f_ut_new_system()
  103. use ISO_C_BINDING
  104. implicit none
  105. interface
  106. type(C_PTR) function c_ut_new_system() bind(C,name='ut_new_system')
  107. use ISO_C_BINDING
  108. implicit none
  109. end function c_ut_new_system
  110. end interface
  111. f_ut_new_system%ptr = c_ut_new_system()
  112. end function f_ut_new_system
  113. !=============================================================================
  114. integer(C_INT) function f_ut_get_status()
  115. use ISO_C_BINDING
  116. implicit none
  117. interface
  118. integer(C_INT) function c_ut_get_status() bind(C,name='ut_get_status')
  119. use ISO_C_BINDING
  120. implicit none
  121. end function c_ut_get_status
  122. end interface
  123. f_ut_get_status = c_ut_get_status()
  124. end function f_ut_get_status
  125. !=============================================================================
  126. subroutine f_ut_set_status(status)
  127. use ISO_C_BINDING
  128. implicit none
  129. integer(C_INT), intent(IN) :: status
  130. interface
  131. subroutine c_ut_set_status(status) bind(C,name='ut_set_status')
  132. use ISO_C_BINDING
  133. implicit none
  134. integer(C_INT), value :: status
  135. end subroutine c_ut_set_status
  136. end interface
  137. call c_ut_set_status(status)
  138. end subroutine f_ut_set_status
  139. !=============================================================================
  140. type(UT_SYSTEM_PTR) function f_ut_get_system(unit1)
  141. use ISO_C_BINDING
  142. implicit none
  143. type(UT_UNIT_PTR), intent(IN) :: unit1
  144. interface
  145. type(C_PTR) function c_ut_get_system(unit1) bind(C,name='ut_get_system')
  146. use ISO_C_BINDING
  147. implicit none
  148. type(C_PTR), value :: unit1
  149. end function c_ut_get_system
  150. end interface
  151. f_ut_get_system%ptr = c_ut_get_system(unit1%ptr)
  152. end function f_ut_get_system
  153. !=============================================================================
  154. type(UT_UNIT_PTR) function f_ut_new_base_unit(ut_system)
  155. use ISO_C_BINDING
  156. implicit none
  157. type(UT_SYSTEM_PTR), intent(IN) :: ut_system
  158. interface
  159. type(C_PTR) function c_ut_new_base_unit(system) bind(C,name='ut_new_base_unit')
  160. use ISO_C_BINDING
  161. implicit none
  162. type(C_PTR), value :: system
  163. end function c_ut_new_base_unit
  164. end interface
  165. f_ut_new_base_unit%ptr = c_ut_new_base_unit(ut_system%ptr)
  166. return
  167. end function f_ut_new_base_unit
  168. !=============================================================================
  169. type(UT_UNIT_PTR) function f_ut_new_dimensionless_unit(ut_system)
  170. use ISO_C_BINDING
  171. implicit none
  172. type(UT_SYSTEM_PTR), intent(IN) :: ut_system
  173. interface
  174. type(C_PTR) function c_ut_new_dimensionless_unit(system) bind(C,name='ut_new_dimensionless_unit')
  175. use ISO_C_BINDING
  176. implicit none
  177. type(C_PTR), value :: system
  178. end function c_ut_new_dimensionless_unit
  179. end interface
  180. f_ut_new_dimensionless_unit%ptr = c_ut_new_dimensionless_unit(ut_system%ptr)
  181. return
  182. end function f_ut_new_dimensionless_unit
  183. !=============================================================================
  184. type(UT_UNIT_PTR) function f_ut_get_dimensionless_unit_one(ut_system)
  185. use ISO_C_BINDING
  186. implicit none
  187. type(UT_SYSTEM_PTR), intent(IN) :: ut_system
  188. interface
  189. type(C_PTR) function c_ut_get_dimensionless_unit_one(system) bind(C,name='ut_get_dimensionless_unit_one')
  190. use ISO_C_BINDING
  191. implicit none
  192. type(C_PTR), value :: system
  193. end function c_ut_get_dimensionless_unit_one
  194. end interface
  195. f_ut_get_dimensionless_unit_one%ptr = c_ut_get_dimensionless_unit_one(ut_system%ptr)
  196. return
  197. end function f_ut_get_dimensionless_unit_one
  198. !=============================================================================
  199. subroutine f_ut_free_system(ut_system)
  200. use ISO_C_BINDING
  201. implicit none
  202. type(UT_SYSTEM_PTR), intent(IN) :: ut_system
  203. interface
  204. subroutine c_ut_free_system(system) bind(C,name='ut_free_system')
  205. use ISO_C_BINDING
  206. implicit none
  207. type(C_PTR), value :: system
  208. end subroutine c_ut_free_system
  209. end interface
  210. call c_ut_free_system(ut_system%ptr)
  211. return
  212. end subroutine f_ut_free_system
  213. !=============================================================================
  214. type(UT_UNIT_PTR) function f_ut_get_unit_by_name(ut_system,name)
  215. use ISO_C_BINDING
  216. implicit none
  217. type(UT_SYSTEM_PTR), intent(IN) :: ut_system
  218. character (len=*), intent(IN) :: name
  219. character (len=1), dimension(len_trim(name)+1), target :: temp
  220. interface
  221. type(C_PTR) function c_ut_get_unit_by_name(ut_system,name) bind(C,name='ut_get_unit_by_name')
  222. use ISO_C_BINDING
  223. implicit none
  224. type(C_PTR), value :: ut_system
  225. type(C_PTR), value :: name
  226. end function c_ut_get_unit_by_name
  227. end interface
  228. temp = transfer( trim(name)//achar(0) , temp )
  229. f_ut_get_unit_by_name%ptr = c_ut_get_unit_by_name(ut_system%ptr,c_loc(temp))
  230. end function f_ut_get_unit_by_name
  231. !=============================================================================
  232. type(UT_UNIT_PTR) function f_ut_get_unit_by_symbol(ut_system,symbol)
  233. use ISO_C_BINDING
  234. implicit none
  235. type(UT_SYSTEM_PTR), intent(IN) :: ut_system
  236. character (len=*), intent(IN) :: symbol
  237. character (len=1), dimension(len_trim(symbol)+1), target :: temp
  238. interface
  239. type(C_PTR) function c_ut_get_unit_by_symbol(ut_system,symbol) bind(C,name='ut_get_unit_by_symbol')
  240. use ISO_C_BINDING
  241. implicit none
  242. type(C_PTR), value :: ut_system
  243. type(C_PTR), value :: symbol
  244. end function c_ut_get_unit_by_symbol
  245. end interface
  246. temp = transfer( trim(symbol)//achar(0) , temp )
  247. f_ut_get_unit_by_symbol%ptr = c_ut_get_unit_by_symbol(ut_system%ptr,c_loc(temp))
  248. end function f_ut_get_unit_by_symbol
  249. !=============================================================================
  250. integer(C_INT) function f_ut_map_name_to_unit(symbol,encoding,ut_unit)
  251. use ISO_C_BINDING
  252. implicit none
  253. character (len=*), intent(IN) :: symbol
  254. integer(C_INT), intent(IN) :: encoding
  255. type(UT_UNIT_PTR), intent(IN) :: ut_unit
  256. character (len=1), dimension(len_trim(symbol)+1), target :: temp
  257. interface
  258. integer(C_INT) function c_ut_map_name_to_unit(symbol,encoding,ut_unit) bind(C,name='ut_map_name_to_unit')
  259. use ISO_C_BINDING
  260. implicit none
  261. type(C_PTR), value :: symbol
  262. integer(C_INT), value :: encoding
  263. type(C_PTR), value :: ut_unit
  264. end function c_ut_map_name_to_unit
  265. end interface
  266. temp = transfer( trim(symbol)//achar(0) , temp )
  267. f_ut_map_name_to_unit = c_ut_map_name_to_unit(c_loc(temp),encoding,ut_unit%ptr)
  268. end function f_ut_map_name_to_unit
  269. !=============================================================================
  270. integer(C_INT) function f_ut_map_unit_to_name(ut_unit,symbol,encoding)
  271. use ISO_C_BINDING
  272. implicit none
  273. type(UT_UNIT_PTR), intent(IN) :: ut_unit
  274. character (len=*), intent(IN) :: symbol
  275. integer(C_INT), intent(IN) :: encoding
  276. character (len=1), dimension(len_trim(symbol)+1), target :: temp
  277. interface
  278. integer(C_INT) function c_ut_map_unit_to_name(ut_unit,symbol,encoding) bind(C,name='ut_map_unit_to_name')
  279. use ISO_C_BINDING
  280. implicit none
  281. type(C_PTR), value :: ut_unit
  282. type(C_PTR), value :: symbol
  283. integer(C_INT), value :: encoding
  284. end function c_ut_map_unit_to_name
  285. end interface
  286. temp = transfer( trim(symbol)//achar(0) , temp )
  287. f_ut_map_unit_to_name = c_ut_map_unit_to_name(ut_unit%ptr,c_loc(temp),encoding)
  288. end function f_ut_map_unit_to_name
  289. !=============================================================================
  290. integer(C_INT) function f_ut_unmap_name_to_unit(ut_system,symbol,encoding)
  291. use ISO_C_BINDING
  292. implicit none
  293. type(UT_SYSTEM_PTR), intent(IN) :: ut_system
  294. character (len=*), intent(IN) :: symbol
  295. integer(C_INT), intent(IN) :: encoding
  296. character (len=1), dimension(len_trim(symbol)+1), target :: temp
  297. interface
  298. integer(C_INT) function c_ut_unmap_name_to_unit(ut_system,symbol,encoding) bind(C,name='ut_unmap_name_to_unit')
  299. use ISO_C_BINDING
  300. implicit none
  301. type(C_PTR), value :: ut_system
  302. type(C_PTR), value :: symbol
  303. integer(C_INT), value :: encoding
  304. end function c_ut_unmap_name_to_unit
  305. end interface
  306. temp = transfer( trim(symbol)//achar(0) , temp )
  307. f_ut_unmap_name_to_unit = c_ut_unmap_name_to_unit(ut_system%ptr,c_loc(temp),encoding)
  308. end function f_ut_unmap_name_to_unit
  309. !=============================================================================
  310. integer(C_INT) function f_ut_unmap_unit_to_name(ut_unit,encoding)
  311. use ISO_C_BINDING
  312. implicit none
  313. type(UT_UNIT_PTR), intent(IN) :: ut_unit
  314. integer(C_INT), intent(IN) :: encoding
  315. interface
  316. integer(C_INT) function c_ut_unmap_unit_to_name(ut_unit,encoding) bind(C,name='ut_unmap_unit_to_name')
  317. use ISO_C_BINDING
  318. implicit none
  319. type(C_PTR), value :: ut_unit
  320. integer(C_INT), value :: encoding
  321. end function c_ut_unmap_unit_to_name
  322. end interface
  323. f_ut_unmap_unit_to_name = c_ut_unmap_unit_to_name(ut_unit%ptr,encoding)
  324. end function f_ut_unmap_unit_to_name
  325. !=============================================================================
  326. integer(C_INT) function f_ut_map_symbol_to_unit(symbol,encoding,ut_unit)
  327. use ISO_C_BINDING
  328. implicit none
  329. character (len=*), intent(IN) :: symbol
  330. integer(C_INT), intent(IN) :: encoding
  331. type(UT_UNIT_PTR), intent(IN) :: ut_unit
  332. character (len=1), dimension(len_trim(symbol)+1), target :: temp
  333. interface
  334. integer(C_INT) function c_ut_map_symbol_to_unit(symbol,encoding,ut_unit) bind(C,name='ut_map_symbol_to_unit')
  335. use ISO_C_BINDING
  336. implicit none
  337. type(C_PTR), value :: symbol
  338. integer(C_INT), value :: encoding
  339. type(C_PTR), value :: ut_unit
  340. end function c_ut_map_symbol_to_unit
  341. end interface
  342. temp = transfer( trim(symbol)//achar(0) , temp )
  343. f_ut_map_symbol_to_unit = c_ut_map_symbol_to_unit(c_loc(temp),encoding,ut_unit%ptr)
  344. end function f_ut_map_symbol_to_unit
  345. !=============================================================================
  346. integer(C_INT) function f_ut_map_unit_to_symbol(ut_unit,symbol,encoding)
  347. use ISO_C_BINDING
  348. implicit none
  349. type(UT_UNIT_PTR), intent(IN) :: ut_unit
  350. character (len=*), intent(IN) :: symbol
  351. integer(C_INT), intent(IN) :: encoding
  352. character (len=1), dimension(len_trim(symbol)+1), target :: temp
  353. interface
  354. integer(C_INT) function c_ut_map_unit_to_symbol(ut_unit,symbol,encoding) bind(C,name='ut_map_unit_to_symbol')
  355. use ISO_C_BINDING
  356. implicit none
  357. type(C_PTR), value :: ut_unit
  358. type(C_PTR), value :: symbol
  359. integer(C_INT), value :: encoding
  360. end function c_ut_map_unit_to_symbol
  361. end interface
  362. temp = transfer( trim(symbol)//achar(0) , temp )
  363. f_ut_map_unit_to_symbol = c_ut_map_unit_to_symbol(ut_unit%ptr,c_loc(temp),encoding)
  364. end function f_ut_map_unit_to_symbol
  365. !=============================================================================
  366. integer(C_INT) function f_ut_unmap_symbol_to_unit(ut_system,symbol,encoding)
  367. use ISO_C_BINDING
  368. implicit none
  369. type(UT_SYSTEM_PTR), intent(IN) :: ut_system
  370. character (len=*), intent(IN) :: symbol
  371. integer(C_INT), intent(IN) :: encoding
  372. character (len=1), dimension(len_trim(symbol)+1), target :: temp
  373. interface
  374. integer(C_INT) function c_ut_unmap_symbol_to_unit(ut_system,symbol,encoding) bind(C,name='ut_unmap_symbol_to_unit')
  375. use ISO_C_BINDING
  376. implicit none
  377. type(C_PTR), value :: ut_system
  378. type(C_PTR), value :: symbol
  379. integer(C_INT), value :: encoding
  380. end function c_ut_unmap_symbol_to_unit
  381. end interface
  382. temp = transfer( trim(symbol)//achar(0) , temp )
  383. f_ut_unmap_symbol_to_unit = c_ut_unmap_symbol_to_unit(ut_system%ptr,c_loc(temp),encoding)
  384. end function f_ut_unmap_symbol_to_unit
  385. !=============================================================================
  386. integer(C_INT) function f_ut_unmap_unit_to_symbol(ut_unit,encoding)
  387. use ISO_C_BINDING
  388. implicit none
  389. type(UT_UNIT_PTR), intent(IN) :: ut_unit
  390. integer(C_INT), intent(IN) :: encoding
  391. interface
  392. integer(C_INT) function c_ut_unmap_unit_to_symbol(ut_unit,encoding) bind(C,name='ut_unmap_unit_to_symbol')
  393. use ISO_C_BINDING
  394. implicit none
  395. type(C_PTR), value :: ut_unit
  396. integer(C_INT), value :: encoding
  397. end function c_ut_unmap_unit_to_symbol
  398. end interface
  399. f_ut_unmap_unit_to_symbol = c_ut_unmap_unit_to_symbol(ut_unit%ptr,encoding)
  400. end function f_ut_unmap_unit_to_symbol
  401. !=============================================================================
  402. integer(C_INT) function f_ut_set_second(unit1)
  403. use ISO_C_BINDING
  404. implicit none
  405. type(UT_UNIT_PTR), intent(IN) :: unit1
  406. interface
  407. integer(C_INT) function c_ut_set_second(unit1) bind(C,name='ut_set_second')
  408. use ISO_C_BINDING
  409. implicit none
  410. type(C_PTR), value :: unit1
  411. end function c_ut_set_second
  412. end interface
  413. f_ut_set_second = c_ut_set_second(unit1%ptr)
  414. end function f_ut_set_second
  415. !=============================================================================
  416. integer(C_INT) function f_ut_add_name_prefix(ut_system,name,value)
  417. use ISO_C_BINDING
  418. implicit none
  419. type(UT_SYSTEM_PTR), intent(IN) :: ut_system
  420. character (len=*), intent(IN) :: name
  421. real(C_DOUBLE), intent(IN) :: value
  422. character (len=1), dimension(len_trim(name)+1), target :: temp
  423. interface
  424. integer(C_INT) function c_ut_add_name_prefix(ut_system,name,value) bind(C,name='ut_add_name_prefix')
  425. use ISO_C_BINDING
  426. implicit none
  427. type(C_PTR), value :: ut_system
  428. type(C_PTR), value :: name
  429. real(C_DOUBLE), value :: value
  430. end function c_ut_add_name_prefix
  431. end interface
  432. temp = transfer( trim(name)//achar(0) , temp )
  433. f_ut_add_name_prefix = c_ut_add_name_prefix(ut_system%ptr,c_loc(temp),value)
  434. end function f_ut_add_name_prefix
  435. !=============================================================================
  436. integer(C_INT) function f_ut_add_symbol_prefix(ut_system,name,value)
  437. use ISO_C_BINDING
  438. implicit none
  439. type(UT_SYSTEM_PTR), intent(IN) :: ut_system
  440. character (len=*), intent(IN) :: name
  441. real(C_DOUBLE), intent(IN) :: value
  442. character (len=1), dimension(len_trim(name)+1), target :: temp
  443. interface
  444. integer(C_INT) function c_ut_add_symbol_prefix(ut_system,name,value) bind(C,name='ut_add_symbol_prefix')
  445. use ISO_C_BINDING
  446. implicit none
  447. type(C_PTR), value :: ut_system
  448. type(C_PTR), value :: name
  449. real(C_DOUBLE), value :: value
  450. end function c_ut_add_symbol_prefix
  451. end interface
  452. temp = transfer( trim(name)//achar(0) , temp )
  453. f_ut_add_symbol_prefix = c_ut_add_symbol_prefix(ut_system%ptr,c_loc(temp),value)
  454. end function f_ut_add_symbol_prefix
  455. !=============================================================================
  456. type(UT_UNIT_PTR) function f_ut_offset_by_time(unit1,origin)
  457. use ISO_C_BINDING
  458. implicit none
  459. type(UT_UNIT_PTR), intent(IN) :: unit1
  460. real(C_DOUBLE), intent(IN) :: origin
  461. interface
  462. type(C_PTR) function c_ut_offset_by_time(unit1,origin) bind(C,name='ut_offset_by_time')
  463. use ISO_C_BINDING
  464. implicit none
  465. type(C_PTR), value :: unit1
  466. real(C_DOUBLE), value :: origin
  467. end function c_ut_offset_by_time
  468. end interface
  469. f_ut_offset_by_time%ptr = c_ut_offset_by_time(unit1%ptr,origin)
  470. end function f_ut_offset_by_time
  471. !=============================================================================
  472. integer function f_ut_format(ut_unit,buffer,options)
  473. use ISO_C_BINDING
  474. implicit none
  475. type(UT_UNIT_PTR), intent(IN) :: ut_unit
  476. character (len=*), intent(OUT) :: buffer
  477. integer, intent(IN) :: options
  478. integer(C_SIZE_T) :: buflen
  479. character (len=1), dimension(len(buffer)), target :: temp
  480. integer(C_INT) :: opt
  481. integer :: i, blen
  482. interface
  483. integer(C_INT) function c_ut_format(ut_unit,buffer,buflen,options) bind(C,name='ut_format')
  484. use ISO_C_BINDING
  485. type(C_PTR), value :: ut_unit
  486. type(C_PTR), value :: buffer
  487. integer(C_SIZE_T), value :: buflen
  488. integer(C_INT), value :: options
  489. end function c_ut_format
  490. end interface
  491. buflen=len(buffer)
  492. opt = options
  493. temp=" "
  494. blen = c_ut_format(ut_unit%ptr,c_loc(temp),buflen,opt)
  495. f_ut_format = blen
  496. if(blen <= 0) then
  497. buffer="ERROR"
  498. return
  499. endif
  500. buffer = ""
  501. ! do i=1,blen
  502. ! buffer(i:i)=temp(i)
  503. ! enddo
  504. buffer(1:blen)=transfer(temp(1:blen),buffer)
  505. end function f_ut_format
  506. !=============================================================================
  507. type(UT_UNIT_PTR) function f_ut_parse(ut_system,symbol,charset)
  508. use ISO_C_BINDING
  509. implicit none
  510. type(UT_SYSTEM_PTR), intent(IN) :: ut_system
  511. character (len=*), intent(IN) :: symbol
  512. integer, intent(IN) :: charset ! ignored for the time being
  513. integer(C_INT) :: encoding
  514. character (len=1), dimension(len_trim(symbol)+1), target :: temp
  515. interface
  516. type(C_PTR) function c_ut_parse(ut_system,symbol,encoding) bind(C,name='ut_parse')
  517. use ISO_C_BINDING
  518. implicit none
  519. type(C_PTR), value :: ut_system
  520. type(C_PTR), value :: symbol
  521. integer(C_INT), value :: encoding
  522. end function c_ut_parse
  523. end interface
  524. ! encoding = UT_ASCII
  525. encoding = charset
  526. temp = transfer( trim(symbol)//achar(0) , temp )
  527. f_ut_parse%ptr = c_ut_parse(ut_system%ptr,c_loc(temp),encoding)
  528. end function f_ut_parse
  529. !=============================================================================
  530. subroutine f_ut_free(ut_unit)
  531. use ISO_C_BINDING
  532. implicit none
  533. type(UT_UNIT_PTR), intent(IN) :: ut_unit
  534. interface
  535. subroutine c_ut_free(ut_unit) bind(C,name='ut_free')
  536. use ISO_C_BINDING
  537. implicit none
  538. type(C_PTR), value :: ut_unit
  539. end subroutine c_ut_free
  540. end interface
  541. call c_ut_free(ut_unit%ptr)
  542. return
  543. end subroutine f_ut_free
  544. !=============================================================================
  545. integer function f_ut_compare(unit1,unit2)
  546. use ISO_C_BINDING
  547. implicit none
  548. type(UT_UNIT_PTR), intent(IN) :: unit1,unit2
  549. interface
  550. integer(C_INT) function c_ut_compare(unit1,unit2) bind(C,name='ut_compare')
  551. use ISO_C_BINDING
  552. implicit none
  553. type(C_PTR), value :: unit1
  554. type(C_PTR), value :: unit2
  555. end function c_ut_compare
  556. end interface
  557. f_ut_compare = c_ut_compare(unit1%ptr,unit2%ptr)
  558. end function f_ut_compare
  559. !=============================================================================
  560. logical function f_ut_same_system(unit1,unit2)
  561. use ISO_C_BINDING
  562. implicit none
  563. type(UT_UNIT_PTR), intent(IN) :: unit1,unit2
  564. interface
  565. integer(C_INT) function c_ut_same_system(unit1,unit2) bind(C,name='ut_same_system')
  566. use ISO_C_BINDING
  567. implicit none
  568. type(C_PTR), value :: unit1
  569. type(C_PTR), value :: unit2
  570. end function c_ut_same_system
  571. end interface
  572. f_ut_same_system = c_ut_same_system(unit1%ptr,unit2%ptr) .ne. 0
  573. end function f_ut_same_system
  574. !=============================================================================
  575. logical function f_ut_is_dimensionless(unit1)
  576. use ISO_C_BINDING
  577. implicit none
  578. type(UT_UNIT_PTR), intent(IN) :: unit1
  579. interface
  580. integer(C_INT) function c_ut_is_dimensionless(unit1) bind(C,name='ut_is_dimensionless')
  581. use ISO_C_BINDING
  582. implicit none
  583. type(C_PTR), value :: unit1
  584. end function c_ut_is_dimensionless
  585. end interface
  586. f_ut_is_dimensionless = c_ut_is_dimensionless(unit1%ptr) .ne. 0
  587. end function f_ut_is_dimensionless
  588. !=============================================================================
  589. logical function f_ut_are_convertible(unit1,unit2)
  590. use ISO_C_BINDING
  591. implicit none
  592. type(UT_UNIT_PTR), intent(IN) :: unit1,unit2
  593. interface
  594. integer(C_INT) function c_ut_are_convertible(unit1,unit2) bind(C,name='ut_are_convertible')
  595. use ISO_C_BINDING
  596. implicit none
  597. type(C_PTR), value :: unit1
  598. type(C_PTR), value :: unit2
  599. end function c_ut_are_convertible
  600. end interface
  601. f_ut_are_convertible = c_ut_are_convertible(unit1%ptr,unit2%ptr) .ne. 0
  602. end function f_ut_are_convertible
  603. !=============================================================================
  604. type(UT_UNIT_PTR) function f_ut_root(unit1,base)
  605. use ISO_C_BINDING
  606. implicit none
  607. type(UT_UNIT_PTR), intent(IN) :: unit1
  608. integer(C_INT), intent(IN) :: base
  609. interface
  610. type(C_PTR) function c_ut_root(unit1,base) bind(C,name='ut_root')
  611. use ISO_C_BINDING
  612. implicit none
  613. type(C_PTR), value :: unit1
  614. integer(C_INT), value :: base
  615. end function c_ut_root
  616. end interface
  617. f_ut_root%ptr = c_ut_root(unit1%ptr,base)
  618. end function f_ut_root
  619. !=============================================================================
  620. type(UT_UNIT_PTR) function f_ut_raise(unit1,base)
  621. use ISO_C_BINDING
  622. implicit none
  623. type(UT_UNIT_PTR), intent(IN) :: unit1
  624. integer(C_INT), intent(IN) :: base
  625. interface
  626. type(C_PTR) function c_ut_raise(unit1,base) bind(C,name='ut_raise')
  627. use ISO_C_BINDING
  628. implicit none
  629. type(C_PTR), value :: unit1
  630. integer(C_INT), value :: base
  631. end function c_ut_raise
  632. end interface
  633. f_ut_raise%ptr = c_ut_raise(unit1%ptr,base)
  634. end function f_ut_raise
  635. !=============================================================================
  636. type(UT_UNIT_PTR) function f_ut_offset(unit1,base)
  637. use ISO_C_BINDING
  638. implicit none
  639. type(UT_UNIT_PTR), intent(IN) :: unit1
  640. real(C_DOUBLE), intent(IN) :: base
  641. interface
  642. type(C_PTR) function c_ut_offset(unit1,base) bind(C,name='ut_offset')
  643. use ISO_C_BINDING
  644. implicit none
  645. type(C_PTR), value :: unit1
  646. real(C_DOUBLE), value :: base
  647. end function c_ut_offset
  648. end interface
  649. f_ut_offset%ptr = c_ut_offset(unit1%ptr,base)
  650. end function f_ut_offset
  651. !=============================================================================
  652. type(UT_UNIT_PTR) function f_ut_scale(base,unit1)
  653. use ISO_C_BINDING
  654. implicit none
  655. type(UT_UNIT_PTR), intent(IN) :: unit1
  656. real(C_DOUBLE), intent(IN) :: base
  657. interface
  658. type(C_PTR) function c_ut_scale(base,unit1) bind(C,name='ut_scale')
  659. use ISO_C_BINDING
  660. implicit none
  661. type(C_PTR), value :: unit1
  662. real(C_DOUBLE), value :: base
  663. end function c_ut_scale
  664. end interface
  665. f_ut_scale%ptr = c_ut_scale(base,unit1%ptr)
  666. end function f_ut_scale
  667. !=============================================================================
  668. type(UT_UNIT_PTR) function f_ut_log(base,unit1)
  669. use ISO_C_BINDING
  670. implicit none
  671. type(UT_UNIT_PTR), intent(IN) :: unit1
  672. real(C_DOUBLE), intent(IN) :: base
  673. interface
  674. type(C_PTR) function c_ut_log(base,unit1) bind(C,name='ut_log')
  675. use ISO_C_BINDING
  676. implicit none
  677. type(C_PTR), value :: unit1
  678. real(C_DOUBLE), value :: base
  679. end function c_ut_log
  680. end interface
  681. f_ut_log%ptr = c_ut_log(base,unit1%ptr)
  682. end function f_ut_log
  683. !=============================================================================
  684. type(UT_UNIT_PTR) function f_ut_clone(unit1)
  685. use ISO_C_BINDING
  686. implicit none
  687. type(UT_UNIT_PTR), intent(IN) :: unit1
  688. interface
  689. type(C_PTR) function c_ut_clone(unit1) bind(C,name='ut_clone')
  690. use ISO_C_BINDING
  691. implicit none
  692. type(C_PTR), value :: unit1
  693. end function c_ut_clone
  694. end interface
  695. f_ut_clone%ptr = c_ut_clone(unit1%ptr)
  696. end function f_ut_clone
  697. !=============================================================================
  698. type(UT_UNIT_PTR) function f_ut_invert(unit1)
  699. use ISO_C_BINDING
  700. implicit none
  701. type(UT_UNIT_PTR), intent(IN) :: unit1
  702. interface
  703. type(C_PTR) function c_ut_invert(unit1) bind(C,name='ut_invert')
  704. use ISO_C_BINDING
  705. implicit none
  706. type(C_PTR), value :: unit1
  707. end function c_ut_invert
  708. end interface
  709. f_ut_invert%ptr = c_ut_invert(unit1%ptr)
  710. end function f_ut_invert
  711. !=============================================================================
  712. type(UT_UNIT_PTR) function f_ut_multiply(unit1,unit2)
  713. use ISO_C_BINDING
  714. implicit none
  715. type(UT_UNIT_PTR), intent(IN) :: unit1,unit2
  716. interface
  717. type(C_PTR) function c_ut_multiply(unit1,unit2) bind(C,name='ut_multiply')
  718. use ISO_C_BINDING
  719. implicit none
  720. type(C_PTR), value :: unit1
  721. type(C_PTR), value :: unit2
  722. end function c_ut_multiply
  723. end interface
  724. f_ut_multiply%ptr = c_ut_multiply(unit1%ptr,unit2%ptr)
  725. end function f_ut_multiply
  726. !=============================================================================
  727. type(UT_UNIT_PTR) function f_ut_divide(unit1,unit2)
  728. use ISO_C_BINDING
  729. implicit none
  730. type(UT_UNIT_PTR), intent(IN) :: unit1,unit2
  731. interface
  732. type(C_PTR) function ut_divide(unit1,unit2) bind(C,name='ut_divide')
  733. use ISO_C_BINDING
  734. implicit none
  735. type(C_PTR), value :: unit1
  736. type(C_PTR), value :: unit2
  737. end function ut_divide
  738. end interface
  739. f_ut_divide%ptr = ut_divide(unit1%ptr,unit2%ptr)
  740. end function f_ut_divide
  741. !=============================================================================
  742. type(CV_CONVERTER_PTR) function f_ut_get_converter(from,to)
  743. use ISO_C_BINDING
  744. implicit none
  745. type(UT_UNIT_PTR), intent(IN) :: from, to
  746. interface
  747. type(C_PTR) function ut_get_converter(from,to) bind(C,name='ut_get_converter')
  748. use ISO_C_BINDING
  749. implicit none
  750. type(C_PTR), value :: from
  751. type(C_PTR), value :: to
  752. end function ut_get_converter
  753. end interface
  754. f_ut_get_converter%ptr = ut_get_converter(from%ptr,to%ptr)
  755. end function f_ut_get_converter
  756. !=============================================================================
  757. subroutine f_cv_free(converter)
  758. use ISO_C_BINDING
  759. implicit none
  760. type(CV_CONVERTER_PTR), intent(IN) :: converter
  761. interface
  762. subroutine cv_free(converter) bind(C,name='cv_free')
  763. use ISO_C_BINDING
  764. implicit none
  765. type(C_PTR), value :: converter
  766. end subroutine cv_free
  767. end interface
  768. call cv_free(converter%ptr)
  769. return
  770. end subroutine f_cv_free
  771. !=============================================================================
  772. real function f_cv_convert_float(converter,what)
  773. use ISO_C_BINDING
  774. implicit none
  775. type(CV_CONVERTER_PTR), intent(IN) :: converter
  776. real(C_FLOAT), intent(IN) :: what
  777. interface
  778. real(C_FLOAT) function cv_convert_float(converter,what) bind(C,name='cv_convert_float')
  779. use ISO_C_BINDING
  780. implicit none
  781. type(C_PTR), value :: converter
  782. real(C_FLOAT), value :: what
  783. end function
  784. end interface
  785. f_cv_convert_float = cv_convert_float(converter%ptr,what)
  786. end function f_cv_convert_float
  787. !=============================================================================
  788. real(C_DOUBLE) function f_cv_convert_double(converter,what)
  789. use ISO_C_BINDING
  790. implicit none
  791. type(CV_CONVERTER_PTR), intent(IN) :: converter
  792. real(C_DOUBLE), intent(IN) :: what
  793. interface
  794. real(C_DOUBLE) function cv_convert_double(converter,what) bind(C,name='cv_convert_double')
  795. use ISO_C_BINDING
  796. implicit none
  797. type(C_PTR), value :: converter
  798. real(C_DOUBLE), value :: what
  799. end function
  800. end interface
  801. f_cv_convert_double = cv_convert_double(converter%ptr,what)
  802. end function f_cv_convert_double
  803. !=============================================================================
  804. subroutine f_cv_convert_floats(converter,what,count,dest)
  805. use ISO_C_BINDING
  806. implicit none
  807. type(CV_CONVERTER_PTR), intent(IN) :: converter
  808. real(C_FLOAT), intent(IN), dimension(*) :: what
  809. real(C_FLOAT), intent(OUT), dimension(*) :: dest
  810. integer, intent(IN) :: count
  811. type(C_PTR) :: dummy
  812. integer(C_SIZE_T) :: temp
  813. interface
  814. type(C_PTR) function cv_convert_floats(converter,what,count,dest) bind(C,name='cv_convert_floats')
  815. use ISO_C_BINDING
  816. implicit none
  817. type(C_PTR), value :: converter
  818. real(C_FLOAT), intent(IN), dimension(*) :: what
  819. real(C_FLOAT), intent(OUT), dimension(*) :: dest
  820. integer(C_SIZE_T), value :: count
  821. end function
  822. end interface
  823. temp = count
  824. dummy = cv_convert_floats(converter%ptr,what,temp,dest)
  825. end subroutine f_cv_convert_floats
  826. !=============================================================================
  827. subroutine f_cv_convert_doubles(converter,what,count,dest)
  828. use ISO_C_BINDING
  829. implicit none
  830. type(CV_CONVERTER_PTR), intent(IN) :: converter
  831. real(C_DOUBLE), intent(IN), dimension(*) :: what
  832. real(C_DOUBLE), intent(OUT), dimension(*) :: dest
  833. integer, intent(IN) :: count
  834. type(C_PTR) :: dummy
  835. integer(C_SIZE_T) :: temp
  836. interface
  837. type(C_PTR) function cv_convert_doubles(converter,what,count,dest) bind(C,name='cv_convert_doubles')
  838. use ISO_C_BINDING
  839. implicit none
  840. type(C_PTR), value :: converter
  841. real(C_DOUBLE), intent(IN), dimension(*) :: what
  842. real(C_DOUBLE), intent(OUT), dimension(*) :: dest
  843. integer(C_SIZE_T), value :: count
  844. end function
  845. end interface
  846. temp = count
  847. dummy = cv_convert_doubles(converter%ptr,what,temp,dest)
  848. end subroutine f_cv_convert_doubles
  849. !=============================================================================
  850. subroutine f_ut_decode_time(time,year,month,day,hour,mimute,second,resolution)
  851. use ISO_C_BINDING
  852. implicit none
  853. real(C_DOUBLE), intent(IN) :: time
  854. integer(C_INT) :: year,month,day,hour,mimute
  855. real(C_DOUBLE) :: second, resolution
  856. interface
  857. subroutine c_ut_decode_time(time,year,month,day,hour,mimute,second,resolution) bind(C,name='ut_decode_time')
  858. use ISO_C_BINDING
  859. implicit none
  860. real(C_DOUBLE), value :: time
  861. integer(C_INT) :: year,month,day,hour,mimute
  862. real(C_DOUBLE) :: second, resolution
  863. end subroutine c_ut_decode_time
  864. end interface
  865. call c_ut_decode_time(time,year,month,day,hour,mimute,second,resolution)
  866. end subroutine f_ut_decode_time
  867. !=============================================================================
  868. real(C_DOUBLE) function f_ut_encode_time(year,month,day,hour,mimute,second)
  869. use ISO_C_BINDING
  870. implicit none
  871. integer(C_INT), intent(IN) :: year,month,day,hour,mimute
  872. real(C_DOUBLE), intent(IN) :: second
  873. interface
  874. real(C_DOUBLE) function c_ut_encode_time(year,month,day,hour,mimute,second) bind(C,name='ut_encode_time')
  875. use ISO_C_BINDING
  876. implicit none
  877. integer(C_INT), value :: year,month,day,hour,mimute
  878. real(C_DOUBLE), value :: second
  879. end function c_ut_encode_time
  880. end interface
  881. f_ut_encode_time = c_ut_encode_time(year,month,day,hour,mimute,second)
  882. end function f_ut_encode_time
  883. !=============================================================================
  884. real(C_DOUBLE) function f_ut_encode_date(year,month,day)
  885. use ISO_C_BINDING
  886. implicit none
  887. integer(C_INT), intent(IN) :: year,month,day
  888. interface
  889. real(C_DOUBLE) function c_ut_encode_date(year,month,day) bind(C,name='ut_encode_date')
  890. use ISO_C_BINDING
  891. implicit none
  892. integer(C_INT), value :: year,month,day
  893. end function c_ut_encode_date
  894. end interface
  895. f_ut_encode_date = c_ut_encode_date(year,month,day)
  896. end function f_ut_encode_date
  897. !=============================================================================
  898. real(C_DOUBLE) function f_ut_encode_clock(hour,mimute,second)
  899. use ISO_C_BINDING
  900. implicit none
  901. integer(C_INT), intent(IN) :: hour,mimute
  902. real(C_DOUBLE), intent(IN) :: second
  903. interface
  904. real(C_DOUBLE) function c_ut_encode_clock(hour,mimute,second) bind(C,name='ut_encode_clock')
  905. use ISO_C_BINDING
  906. implicit none
  907. integer(C_INT), value :: hour,mimute
  908. real(C_DOUBLE), value :: second
  909. end function c_ut_encode_clock
  910. end interface
  911. f_ut_encode_clock = c_ut_encode_clock(hour,mimute,second)
  912. end function f_ut_encode_clock
  913. !=============================================================================
  914. character(len=256) function f_ut_get_name(ut_unit,encoding)
  915. use ISO_C_BINDING
  916. implicit none
  917. type(UT_UNIT_PTR), intent(IN) :: ut_unit
  918. integer(C_INT), intent(IN) :: encoding
  919. type(C_PTR) :: ptr
  920. character(len=1), DIMENSION(:), pointer :: c_temp
  921. character(len=256) :: s_temp
  922. integer :: i
  923. interface
  924. type(C_PTR) function c_ut_get_name(ut_unit,encoding) bind(C,name='ut_get_name')
  925. use ISO_C_BINDING
  926. implicit none
  927. type(C_PTR), value :: ut_unit
  928. integer(C_INT), value :: encoding
  929. end function c_ut_get_name
  930. end interface
  931. s_temp = ''
  932. ptr = c_ut_get_name(ut_unit%ptr,encoding)
  933. if(C_ASSOCIATED(ptr)) then
  934. call c_f_pointer(ptr,c_temp,[256])
  935. do i=1,256
  936. if(c_temp(i) == achar(0)) exit
  937. s_temp(i:i) = c_temp(i)
  938. enddo
  939. else
  940. s_temp="NoName"
  941. endif
  942. f_ut_get_name = s_temp
  943. end function f_ut_get_name
  944. !=============================================================================
  945. character(len=256) function f_ut_get_symbol(ut_unit,encoding)
  946. use ISO_C_BINDING
  947. implicit none
  948. type(UT_UNIT_PTR), intent(IN) :: ut_unit
  949. integer(C_INT), intent(IN) :: encoding
  950. type(C_PTR) :: ptr
  951. character(len=1), DIMENSION(:), pointer :: c_temp
  952. character(len=256) :: s_temp
  953. integer :: i
  954. interface
  955. type(C_PTR) function c_ut_get_symbol(ut_unit,encoding) bind(C,name='ut_get_symbol')
  956. use ISO_C_BINDING
  957. implicit none
  958. type(C_PTR), value :: ut_unit
  959. integer(C_INT), value :: encoding
  960. end function c_ut_get_symbol
  961. end interface
  962. s_temp = ''
  963. ptr = c_ut_get_symbol(ut_unit%ptr,encoding)
  964. if(C_ASSOCIATED(ptr)) then
  965. call c_f_pointer(ptr,c_temp,[256])
  966. do i=1,256
  967. if(c_temp(i) == achar(0)) exit
  968. s_temp(i:i) = c_temp(i)
  969. enddo
  970. else
  971. s_temp="NoSymbol"
  972. endif
  973. f_ut_get_symbol = s_temp
  974. end function f_ut_get_symbol
  975. !! const char* ut_get_name (const ut_unit* unit, ut_encoding encoding)
  976. !! const char* ut_get_symbol (const ut_unit* unit, ut_encoding encoding)
  977. !=============================================================================
  978. !=============================================================================
  979. !=============================================================================
  980. !=============================================================================
  981. end module f_udunits_2