Go Back   The UNIX and Linux Forums > Top Forums > Programming


Programming Post questions about C, C++, Java, SQL, and other programming languages here.

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 10-23-2012
Registered User
 
Join Date: Dec 2009
Location: London
Posts: 776
Thanks: 51
Thanked 6 Times in 6 Posts
Deciphering a tag character string

I have a string, eg 7f30.3 and I want to store things in the following way


Code:
npos = 7
decform = true
width = 30
ndp = 3

I need to read each character one by one. I am coding in fortran but I can try to code it should answer be given in C in the above way.
Sponsored Links
    #2  
Old 10-23-2012
Mead Rotor
 
Join Date: Aug 2005
Location: Saskatchewan
Posts: 16,374
Thanks: 491
Thanked 2,535 Times in 2,418 Posts
how do you get 'true' from that?
Sponsored Links
    #3  
Old 10-23-2012
Registered User
 
Join Date: Dec 2009
Location: London
Posts: 776
Thanks: 51
Thanked 6 Times in 6 Posts
I meant set decform = .true. if 'f' is encountered


I got something to work as follows:


Code:
isChar = .false. 
tag = "17f30.2" 
n = LEN_TRIM(tag) 
print '(A,A,A,I1)', 'tag = ', tag(:n), ', n = ', n 

j = 0 
do i = 1, n   
  if ( index('0123456789',tag(i:i)) > 0 ) then     
    j = j + 1   
  else
    exit
  endif
enddo 

print *, 'j = ', j 
npl = 0 
itmp = 0 
k = j 

do i = 1, j     
  read(tag(i:i),*) itmp     
  print *, tag(i:i)     
  npl = npl + (itmp * (10 ** (k-1)) )     
  k = k - 1 
enddo

print *, 'npl = ', npl 
print *, ' ' 

k = 0 
do i = j+2, n   
  if ( index('0123456789',tag(i:i)) > 0 ) then
    k = k + 1
  else
    exit
  endif 
enddo 

print *, 'k = ', k 
iwid = 0 
itmp = 0 

l = k 
print *, j+2, j+2+k-1 
do i = j+2, j+2+k-1     
  read(tag(i:i),*) itmp     
  print *, tag(i:i)     
  iwid = iwid + (itmp * (10 ** (l-1)) )     
  l = l - 1 
enddo 

print *, 'iwid = ', iwid

Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
need help deciphering this if statement Straitsfan Shell Programming and Scripting 8 12-06-2010 02:09 PM
Need help deciphering this Straitsfan UNIX for Dummies Questions & Answers 3 04-28-2010 06:44 PM
Korn: How to loop through a string character by character shew01 Shell Programming and Scripting 10 12-02-2008 06:58 AM
Help deciphering script bbbngowc Shell Programming and Scripting 3 01-16-2008 12:57 PM
converting character string to hex string axes Programming 5 09-20-2006 01:04 PM



All times are GMT -4. The time now is 04:44 PM.