Dan's example of problems with SDBG ( or is it SDBG64 ? ) has provided a number of questions for me about how to convert to /64. It also shows some interesting problems accessing the registry. His example code is use mswin Integer, external :: processor_id jj= processor_id () end !--------------------------------
integer function processor_id ()
!
! With thanks to John Horspool 2008-04-02
!
use mswin
CHARACTER*400 LDATA
CHARACTER*80 getenv@, IDENTIFIER
CHARACTER*80 CPU_stepping, CPU_description
integer n_processorsTotalGetEnv
character*256 ResultsToSave(10)
integer iVersionOfTesrResFile
LSTR=400
k = REGOPENKEYEX(HKEY_LOCAL_MACHINE, &
'HARDWARE\DESCRIPTION\System\CentralProcessor\0', 0,KEY_READ,MyKey)
CPU_description= ' N/A '
if (MyKey.GT.0) then
k = REGQUERYVALUEEX(MyKey,'ProcessorNameString', &
CORE4(0),CORE4(0),LDATA,LSTR)
! WRITE(*,'(a,a)')' Processor : ', LDATA(1:LSTR)
CPU_description = LDATA(1:min(80,LSTR))
endif
k = REGCLOSEKEY(MyKey)
! write(*,*) getenv@('PROCESSOR_IDENTIFIER')
! write(*,*) 'Number of cores=', getenv@('NUMBER_OF_PROCESSORS')
READ(getenv@('NUMBER_OF_PROCESSORS'),*)n_processorsTotalGetEnv
Write (*,*) ' Number of Processors/cores/threads= ', &
n_processorsTotalGetEnv, ' ', getenv@('PROCESSOR_IDENTIFIER')
Read (getenv@('PROCESSOR_IDENTIFIER'),'(a)') CPU_stepping
processor_id=2
end function
I have a number of questions about this example:
Is the use of a 'system' or intrinsic character function valid in an internal READ, eg 'READ(getenv@('NUMBER_OF_PROCESSORS'),)n_processorsTotalGetEnv ' I would use a character? variable first, as below, but is it necessary ? IDENTIFIER = getenv@('NUMBER_OF_PROCESSORS') READ(IDENTIFIER,*) n_processorsTotalGetEnv '
When converting the following to /64, does 'CORE4(0)' need to be changed for 64-bit addressing ? It appears to work. ' k = REGQUERYVALUEEX(MyKey,'ProcessorNameString', & CORE4(0),CORE4(0),LDATA,LSTR) '
The use of ' CHARACTER*80 getenv@, IDENTIFIER ' does not work well for me. What do we do for environment variables that are longer than 80 characters, eg PATH. Should getenv@ be declared as external, or not declared at all ?
I included extra code to get the system MHz from the registry, as: integer4 LSTR, k, myKey, word_type, cpu_mhz INTEGER2 CPU_xx(2) integer1 kkkk(4) equivalence ( CPU_xx, kkkk ) ... word_type = 0 CPU_xx = 0 LSTR = 4 k = REGQUERYVALUEEX (MyKey, '~MHz', CORE4(0), word_type, CPU_xx, LSTR) write (,) 'word_type=',word_type, cpu_xx, lstr, k CPU_MHz = cpu_xx(1) WRITE (,'(i0,1x,i0,a,i8)') k, Lstr,' MHz : ', CPU_MHz, kkkk
~MHz is listed as a REG_DWORD In this call word_type indicates the result is a Dword (4-byte?), but the value returned is 2-byte then padded with 2 spaces. I can't explain this result either.
Any suggestions ?
Thanks and thinking of John Horspool
John