A Space & astronomy forum. SpaceBanter.com

Go Back   Home » SpaceBanter.com forum » Astronomy and Astrophysics » FITS
Site Map Home Authors List Search Today's Posts Mark Forums Read Web Partners

Resetting Cursor



 
 
Thread Tools Display Modes
  #1  
Old December 16th 08, 06:53 PM posted to sci.astro.fits
lsitongia
external usenet poster
 
Posts: 2
Default Resetting Cursor

I'm using Cursor to iterate over a Header. I find that nextCard
starts returning cards at the location in the Header at which my last
get found a card. For example, if I getIntValue for something in the
Header, then the Cursor starts from where that card was found.

How do I reset the Cursor to the beginning of the Header?

Thanks,
==Leonard
  #2  
Old December 17th 08, 04:46 PM posted to sci.astro.fits
Tom McGlynn
external usenet poster
 
Posts: 3
Default [fitsbits] Resetting Cursor

lsitongia wrote:
I'm using Cursor to iterate over a Header. I find that nextCard
starts returning cards at the location in the Header at which my last
get found a card. For example, if I getIntValue for something in the
Header, then the Cursor starts from where that card was found.

How do I reset the Cursor to the beginning of the Header?

Thanks,
==Leonard
_______________________________________________
fitsbits mailing list

http://listmgr.cv.nrao.edu/mailman/listinfo/fitsbits



Hi Leonard,

While I suspect that you are referring to use of the Java FITS package
that I wrote (or one derived from it), you might want to be a little
more specific about the context of the software and version you are using.

If you are using the nom.tam.fits package then you should be able to
iterate over the entire header using your own cursors rather than the
one owned by the Header object. E.g., the program below

import nom.tam.fits.*;
import nom.tam.util.*;

public class Test {

public static void main(String[] args) throws Exception {
Fits f = new Fits(args[0]);
BasicHDU hdu = f.readHDU();
Header hdr = hdu.getHeader();

double cv2 = hdr.getDoubleValue("CRVAL2");
System.out.println("CRVAL2 is:" + cv2);

Cursor c1 = hdr.iterator();
cv2 = hdr.getDoubleValue("CRVAL2");
System.out.println("CRVAL2 is:" + cv2);

Cursor c2 = hdr.iterator();
while (c1.hasNext()) {
System.out.println("C1: " + c1.next());
}
System.out.println("\n\n*** second ****\n\n");
while(c2.hasNext()) {
System.out.println("C2: " + c2.next());
}
}
}

yields the following input (where I've suppressed most of the header
lines and replaced them with a ...). Both iterators run over the entire
header despite the getDoubleValue() call.

CRVAL2 is:90.0
CRVAL2 is:90.0
C1: SIMPLE = T / Written by SkyView Thu ...
C1: BITPIX = -64 / 8 byte floating point

...
C1: HISTORY

C1: END



*** second ****


C2: SIMPLE = T / Written by SkyView Thu ...
BITPIX = -64 / 8 byte floating point

...
C2: HISTORY

C2: END


The header object uses its own cursor to keep track of the last row that
the user asked for. That's to handle a situation where, e.g., a user
wants to look at the comment cards that immediately precede or follow a
given keyword. So if you are going to use getXXXValue calls, the best
way to independently iterate over the entire header is something like:

Cursor curs = hdr.iterator();
while (curs.hasNext()) {
HeaderCard hc = (HeaderCard) curs.next();
...
}

The casts are a bit ugly, but all of this was written long before Java
generics were available.

With regard to your previous question regarding the behavior of Cursors
at the end of the header: I'm not quite sure what you are saying here.
I wonder if you are confused by the action of nextCard() which returns
null if you are beyond the end of the header. You can use this via a
loop like:

HeaderCard c = null;
while ( (c=hdr.nextCard()) != null) {
... process card c ...
}

If you have further questions, please feel free to write.

Regards,
Tom McGlynn


  #3  
Old December 18th 08, 02:51 PM posted to sci.astro.fits
Leonard Sitongia
external usenet poster
 
Posts: 1
Default Resetting Cursor

Hi Tom,

Sorry about that. Yes, I'm using your package. Version 0.91. I see
1.0 is out now.

Yes, both of my problems were caused by using nextCard(). I was using
Cursor's hasNext() to loop over the cards, then nextCard() to get the
next card instead of the iterator's next() to get the card it is
pointing to. I'll simply use the interator's next() as you do in your
example.

Thanks!
==Leonard
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Cursor questions lsitongia FITS 0 December 16th 08 06:47 PM


All times are GMT +1. The time now is 09:22 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 SpaceBanter.com.
The comments are property of their posters.