Deciphering a tag character string | Unix Linux Forums | Programming

  Go Back    


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

Deciphering a tag character string

Programming


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 10-23-2012
kristinu kristinu is offline
Registered User
 
Join Date: Dec 2009
Last Activity: 23 October 2014, 12:37 PM EDT
Posts: 858
Thanks: 61
Thanked 8 Times in 8 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
Corona688 Corona688 is offline Forum Staff  
Mead Rotor
 
Join Date: Aug 2005
Last Activity: 30 October 2014, 6:26 PM EDT
Location: Saskatchewan
Posts: 19,733
Thanks: 830
Thanked 3,373 Times in 3,160 Posts
how do you get 'true' from that?
Sponsored Links
    #3  
Old 10-23-2012
kristinu kristinu is offline
Registered User
 
Join Date: Dec 2009
Last Activity: 23 October 2014, 12:37 PM EDT
Posts: 858
Thanks: 61
Thanked 8 Times in 8 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 11:00 AM.